Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
tejendi
Starting Member
2 Posts |
Posted - 2010-09-22 : 11:47:07
|
Hey there peeps, I'm really in need of some help with this thing.Thing is I got two tables:Table a: contains a lot of columns[col1][col2][col3][col4][ and so on], some with and some without content. Those without content does in fact contain 6 whitespaces.Table b: this got two columns [colB1][colB2], none of which contains any whitespacesWhat I need is to look at a single row of table a, base on the content of the first column [x].This was relatively easy to figure out.But I then need to add the content of specific columns from table a [col1][col3][col9][col30][ and so on], to table b, where in table b [colB1] = [x] and [colB2] = one of the columns from table a that doesn’t contain whitespaces.A new row is added in table b for each column in table 6 that have content other than the 6 whitespaces.I've tried to make an example of how it should work, hopefully it will help:Table a:COLa1 COLa2 COLa3 COLa4a 4 b 1 32 43Table b:COLb1 COLb2x 2x 1y 1table b after code with COLb1[a] selected:COLb1 COLb2x 2x 1y 1a 4With COLb1[b] selected:COLb1 COLb2x 2x 1y 1b 1b 32b 43 Looking forward to your replies//Daniel |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-23 : 12:43:42
|
| [code]INSERT INTO TableBSELECT COLa1,COLa2FROM TableAWHERE COLa1=@yourvalueAND LEN(COLa2) >0UNION ALLSELECT COLa1,COLa3FROM TableAWHERE COLa1=@yourvalueAND LEN(COLa3) >0UNION ALLSELECT COLa1,COLa4FROM TableAWHERE COLa1=@yourvalueAND LEN(COLa4) >0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|