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 |
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-03-07 : 09:58:47
|
| Hi, here is something new. Can I use a variable (ex: A) with multiple values in the sentence: insert into "database" (row1, row2...) VALUES(var,var1...)***********************Here is the code*****************************Sub test_database_export()Dim N As IntegerDim connstring As StringDim sqlstring As StringDim data As VariantDim data1 As VariantDim data2 As VariantDim data3 As VariantDim data4 As VariantDim data5 As VariantDim data6 As VariantN = 16Do Until ActiveSheet.Cells(N, 8) = "" N = N + 1Loop N = N - 1data = Range("B16:B" & N & "").Valuedata1 = Range("C16:C" & N & "").Valuedata2 = Range("D16:D" & N & "").Valuedata3 = Range("E16:E" & N & "").Valuedata4 = Range("F16:F" & N & "").Valuedata5 = Range("G16:G" & N & "").Valuedata6 = Range("H16:H" & N & "").Valuesqlstring = "INSERT INTO XXX (Nom, [In], Out_Diner, In_Diner, [Out], Temps_Reel, Temps_arrondi) VALUES ('" & data & "','" & data1 & "','" & data2 & "','" & data3 & "','" & data4 & "','" & data5 & "','" & data6 & "',)"connstring = "ODBC;DSN=XXX;UID=XXX;PWD=XXX;Database=XXX"End Sub//written in VBA\ |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-03-07 : 10:56:55
|
| VALUES will only work with 1 row. You could build UNION ALL statments:insert into XXX (<col list>)Select <val list1> UNION ALLSelect <val list2> UNION ALLSelect <val list3>OR you could create a stored procedure, pass each row as a csv list and let the proc do the inserts.Be One with the OptimizerTG |
 |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-03-07 : 11:18:39
|
| Thank you |
 |
|
|
|
|
|
|
|