Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Updates

Status
Not open for further replies.

ma701sd

IS-IT--Management
Dec 15, 2000
94
GB
Hi,

Im trying to perform multiple upadtes to a row (I have one column already populated by a previous SQL command, but I want to populate the the rest of the fields at another time i.e. now

Currently, the only way I can do it is to enclose each update within a <CFQUERY> but this seems highly in-efficient i.e.:

<CFQUERY NAME = &quot;SiteDataAdded&quot; DATASOURCE = &quot;Online&quot; >
UPDATE UserSpecific
SET Title = '#Form.title#'
WHERE UserName = '#client.UserName#'
</CFQUERY>
<CFQUERY NAME = &quot;SiteDataAdded&quot; DATASOURCE = &quot;Online&quot; >
UPDATE UserSpecific
SET Heading = '#Form.Heading#'
WHERE UserName = '#client.UserName#'
</CFQUERY>


Im sure CF allows this to be done in one go??
What I'm trying to acheive is:

<CFQUERY NAME = &quot;SiteDataAdded&quot; DATASOURCE = &quot;Online&quot; >
UPDATE UserSpecific
SET
Section1Heading1 = '#Form.Section1Heading1#',
Section1Text1 = '#Form.Section1Text1#',
Section1Image1,= '#Form.Section1Image1#'
Section2Heading2, = '#Form.Section2Heading2#
Section2Text2 = '#Form.Section2Text2#'
Section2Image2 = '#Form.Section2Image2#'
WHERE UserName = '#client.UserName#'
</CFQUERY>

Is it a Brackets thing??

Thanks in advance

Sam
 
Hey Sam,

Since you guys are swapping money, I want in :)

The syntax is just

update tablename
set
field1 = '#var1#',
field2 = '#var2#,
...
field10 = '#var10#'

where ..

You've just got some commas in the wrong place in the code you posted. You need commas after these lines
Section1Image1,= '#Form.Section1Image1#'
Section2Heading2, = '#Form.Section2Heading2#
Section2Text2 = '#Form.Section2Text2#'

and you need to remove the commas after the field names on these lines
Section1Image1,= '#Form.Section1Image1#'
Section2Heading2, = '#Form.Section2Heading2#

and you're missing a single quote at the end of this line
Section2Heading2, = '#Form.Section2Heading2#

Hope this helps.
GJ
 
Oops, after critiquing your code, I realized I left off a single quote on my example ;)

field2 = '#var2#,

should be

field2 = '#var2#' ,

GJ
 
OK, 10 bucks for GunJack :). But seriously, GunJack is right, you can do it all in one UPDATE query like he showed. <webguru>iqof188</webguru>
 
Hey iqof188, GJ,

Thanx for your help, I knew there must be an easier way :)

Now, abot the money...hmmmm Who shall I make the check payable to hehehe :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top