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 |
|
dhorn
Starting Member
4 Posts |
Posted - 2010-02-08 : 14:00:20
|
I need to create a sql statement that inserts rows into a tableRecord ID Attrib ID Attrib Value 2 1 True2 2 False2 3 "Texas"3 1 False3 2 True3 3 "Ohio" I have created a new attribute with an ID of 4. So for each record id, I need a new row with the attribute now being 4, and I need to set the attribute value based on the record id. (If it's < 6, attrib value = true, if it's > 6, attrib value = false)Hope that isn't too confusing, but I really don't know where to start. |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-08 : 14:05:15
|
| [code]INSERT INTO MyTable(RecordID, AttribID, AttribValue)SELECT T.RecordID, [AttribID]=4, [AttribValue]= CASE WHEN T.RecordID < 6 THEN True WHEN T.RecordID > 6 THEN False ELSE NULL -- You didn't say what to do when RecordID === 6 ENDFROM( SELECT DISTINCT RecordID FROM MyTable) AS T[/code] |
 |
|
|
|
|
|