SQL 'update' syntax

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

SQL 'update' syntax

Post by pgriffin » Fri Dec 09, 2005 6:12 pm

Ok, so this is not exactly a scripting question...

I need the correct syntax for using UPDATE in a SQL statement where there are several fields (more than 10) that need to be updated with several values.

Update table_name set field1, field2, field3......field10 = value1, value2, value3....value10

I only have examples of updating a single field with a single variable.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Dec 09, 2005 6:15 pm

Usually:

UPDATE table_name SET field1=value1, field2=value2, field3=value3 WHERE etc ....
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Fri Dec 09, 2005 8:39 pm

ok, here's the mess I've made so far....(it's copied from code that actually works, then modified...)

SQLString = _
"Update [PrintSource] set " + _
"[NMFC4] = '" & NC4 & "', [NCDesc4] = '" & NCDesc4 & "', [Class4] = '" & Class4 & "' + _
"[NMFC5] = " & NC5 & ", [NCDesc5] = " & NCDesc5 & ", [Class4] = " & Class5 & + _
"[NMFC6] = " & NC6 & ", [NCDesc6] = " & NCDesc6 & ", [Class4] = " & Class6 & + _
"[NMFC7] = " & NC7 & ", [NCDesc7] = " & NCDesc7 & ", [Class4] = " & Class7 & + _
"[NMFC8] = " & NC8 & ", [NCDesc8] = " & NCDesc8 & ", [Class4] = " & Class8 & + _
"[NMFC9] = " & NC9 & ", [NCDesc9] = " & NCDesc9 & ", [Class4] = " & Class9 & + _
"[NMFC10] = " & NC10 & ", [NCDesc10] = " & NCDesc10 & ", [Class4] = " & Class10



I am able to pass most of what I need to a function which creates the Access record and inserts about half the data, then I need to call another function to fill in the remainder of fields because I can only pass 24 parameters to the function.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts