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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-05-14 : 10:46:12
|
| Dan writes "MS SQL Server 2000 question.Hi, I read and used the sequence or tally table method to extract CSV's from a 1 string passed to me from an ASP page.I have a slightly more complicated problem in that I want to receive a CSV list with sets of values, ie, filename and size. Optionally, I could receive 1 CVS string of filenames and 1 CVS string of filesizes.I was hoping to use one insert statement to populate the 2 columns at a time from the CSV strings.I thought I was getting close to a solution by receiving 2 CSV strings and using 2 sequence columns in the sequence table to insert from both CSV strings at the same time in one insert statement. But, I couldn't get that to work.Is my only resort to use a 2 dimensional array to do this? Or, is there a way to read from 2 CSV strings in one insert operation?Please help." |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2003-05-14 : 10:56:40
|
| What platform are you on...not that it matters...how would you join the data togeteher in the first place, and why can't you put them together in a variable/array...and no you can't do an insert the way your thinking, at least not to my knowledgeI really curious about how you plan on putting the data together...Brett8-) |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-05-14 : 11:39:00
|
| Just loop through the string in your stored proc, and after every 2 commas insert the values into your table.something like (pseudo code mix of VB/SQL):for i = 1 to stringlength if substring(@CSV, i, 1) <> ',' then if commacount = 0 then value1 = value1 + substring(@CSV,i,1) else value2= value2 + substring(@CSV,i,1) else commacount = commacount + 1 end if if commacount = 2 then insert into YourTable (field1, field2) Values (Value1, Value2) commacount = 0 value1 = '' value2 = '' end ifnextsomething like that .. don't take it literally, but you get the idea.Does that make sense? Don't overuse tally tables to make simple things more complex than they need to be. If you have 1 single string to parse and insert, don't use a tally table. Only use them i f you have an entire TABLE of strings to parse and INSERT somewhere.Keep it simple.- Jeff |
 |
|
|
|
|
|
|
|