I need your help to tidy a table. I added two new columns. I would like to fill in these columns(col2, col3) with the data of another one (col1). At the moment, this column contain two values separate by a "val1;val2".
col1 contains a string but sometimes val1 doesn't exist and col1 contains only ";val2"
For every row of this table, I want to split the value in the col1 to separate the date execute this code:
- If(val1 != null) col3 = 1
- col2 = val2
- col1 = val1
Finally, every column contains only one value.
Before the script:
col1 (string) = "tom;car"
After the script:
col1 (string) = "tom"
col2 (string) = "car"
col3 (bit) = "1"
I don't know how to do this directly in SQL Server Management. I would like to create a script to execute this code.
col1
contains42,4711
. And you want to finally have42
in col2 and4711
in col3. Will they be numeric? will they be strings? will they be timestamps or dates? All that can affect the necessary code. - marcothesane