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 |
|
hockheng10
Starting Member
3 Posts |
Posted - 2003-03-12 : 22:19:50
|
| Hi experts!I am very new to "Bulk insert" t-sql, I was trying to use this function to import rows of text in a variable and bulk insert into the database. Somehow what I found from msdn website was command to import from data file, not from variable. Here is the script that I construct in ASP trying to import from variable, but failed.<%data_string = "\tcmr_mbrid\tcmr_accname\tcmr_name\tcmr_handle\tcmr_salute\tcmr_jobtitle\tcmr_email\tcmr_add1\tcmr_add2\tcmr_add2\tcmr_add3\tcmr_phone\tcmr_fax\n\t39\ABC Corp\tTimothy\tTim\tMr\tSenior Marketing Manager\tTimothy@lycos.com\tPenang\tPenang, Malaysia\t04 633 1111\t04 633 1111"sql = "BULK INSERT customer FROM 'c:\data_file.txt' WITH ( FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n' )"conntemp.execute(sql)%>Another thing, should we include the table header name in the first row? Pleas help....Thanks.HHHH |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-03-13 : 03:35:50
|
| >> to import rows of text in a variable and bulk insert into the database??bulk insert imports a text file into a table.You will probably find it easier and more maintainable to put the bulk insert into an sp and pass the filename as a parameter.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
hockheng10
Starting Member
3 Posts |
Posted - 2003-03-14 : 01:06:19
|
| Hi NR,The reason I am targeting to load bulk insert from variable directly is that the long text was constructed in the program before this, and I can save some hassle if I can "Bulk insert" diretctly without outputing that a text file, and let the program grab from there.I am currently using looping to insert that row by row, which I found isn't stable, and consume a lots of resources.Hope you are clear of my situation. Anyone can help?Thanks.HHHH |
 |
|
|
|
|
|
|
|