| Author |
Topic |
|
antman28
Starting Member
10 Posts |
Posted - 2009-04-28 : 13:13:08
|
| I have a table where some rows have attributes separated by line breaks. How can I run a query that creates a new record for an ID with multiple attributes?Current layout...ID Attribute1 Blue Red2 Blue3 Blue Green White4 Blue WhiteDesired layout...ID Attribute1 Blue1 Red2 Blue3 Blue3 Green3 White4 Blue4 White |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
antman28
Starting Member
10 Posts |
Posted - 2009-04-28 : 13:29:24
|
| This data lies in an Access DB. The issue has already been resolved for new entries. However, there are several past entries that need to be separated as explained above. |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-04-28 : 13:35:08
|
| http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rowsChange the commas to char(13) + char(10) and it will work fine. |
 |
|
|
antman28
Starting Member
10 Posts |
Posted - 2009-04-28 : 20:25:56
|
| I get an error message...Syntax error (missing operator) in query expression 'ID <=Len(char(13) + char(10)' + Locations + 'char(13) + char(10)') AND SubString('char(13) + char(10)' + Locations + 'char(13) + char(10)' , ID - 1, 1) = 'char(13) + char(10)' AND CharIndex('char(13) + char(10)' , 'char(13) + char(10)' + Locations +".My full statement reads...SELECT FileName, NullIf(SubString('char(13) + char(10)' + Locations + 'char(13) + char(10)' , ID , CharIndex('char(13) + char(10)' , 'char(13) + char(10)' + Locations + 'char(13) + char(10)' , ID) - ID) , '') AS Location FROM Tally, tblPubs WHERE ID <= Len('char(13) + char(10)' + Locations + 'char(13) + char(10)') AND SubString('char(13) + char(10)' + Locations + 'char(13) + char(10)' , ID - 1, 1) = 'char(13) + char(10)' AND CharIndex('char(13) + char(10)' , 'char(13) + char(10)' + Locations + 'char(13) + char(10)' , ID) - ID > 0INSERT INTO LocationsSplit SELECT FileName, NullIf(SubString('char(13) + char(10)' + Locations + 'char(13) + char(10)' , ID , CharIndex('char(13) + char(10)' , 'char(13) + char(10)' + Locations + 'char(13) + char(10)' , ID) - ID) , '') AS Location FROM Tally, tblPubs WHERE ID <= Len('char(13) + char(10)' + Locations + 'char(13) + char(10)') AND SubString('char(13) + char(10)' + Locations + 'char(13) + char(10)' , ID - 1, 1) = 'char(13) + char(10)' |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-04-28 : 21:04:16
|
| Remove the single quotes around char(13) + char(10). |
 |
|
|
antman28
Starting Member
10 Posts |
Posted - 2009-04-29 : 13:49:56
|
| After removing the quotes I get the same message. If I remove everything starting with "INSERT INTO LocationsSplit..." it lets me save the query. When I open the query however, I get the message "Undefined function 'NullIf' in expression". Any thoughts? Sorry for all the questions, this project just has me stuck. Where should I put the "INSERT INTO..." line? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-04-29 : 13:51:44
|
| where are you doing this? are you using sql server db? |
 |
|
|
antman28
Starting Member
10 Posts |
Posted - 2009-04-29 : 15:52:50
|
| I'm doing it within MS Access |
 |
|
|
antman28
Starting Member
10 Posts |
Posted - 2009-04-30 : 12:19:43
|
| It would be easiest if I could run a query that would create the additional entries as needed. |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-04-30 : 12:24:24
|
| Dupe:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=124814 |
 |
|
|
|