I have table in which there are 8 columns, now what I want is If there is value in column1,column2 and then column3,column4 are null and again column5,column6 value so those column5,6 should be update in column3,and column4. and so on for all different cases. Is that possible to resolved it with single query without using stored procedure or any iterative process.thanks
0
votes
please share all the cases.
– Rohit Kumar
If you only have 6 columns, just write a case statement with all the combinations. If the number of columns is large, then you could build something with unpivot + row_number
– James Z
Rohit, there can be multiple scenarios. 1) I have 12 columns and it is possibility that first 11 are blank and data present in 12th column than i need to move it to column1 2) First 8 columns are blank and 9 has value then 10 is blank and 11,12 has value. 3) column 1,2 has value 3,4 has no value then again 5,6 has value. ... so this n kind of scenarios possible. so each time I have to check if the very starting column has value or not if not then move the value to that column and so on.
– dhaval panchal