Solved

Combine SQL update strings

Posted on 2007-11-27
3
915 Views
Last Modified: 2008-02-01
This string works for what I need, but how can I shorten it for multiple column updates in the same row ?

UpdateString = "UPDATE [BCOMerchantTable] set [MerchName]= '" + NewMerchName + "' WHERE MerchID ='" + MerchID + "' UPDATE [BCOMerchantTable] set [MerchAddress]= '" + NewMerchAddress + "' WHERE MerchID = '" + MerchID + '";
0
Comment
Question by:cbrick04
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
deroby earned 500 total points
ID: 20356359
UpdateString = "UPDATE [BCOMerchantTable] set [MerchName]= '" + NewMerchName + "', [MerchAddress]= '" + NewMerchAddress + "' WHERE MerchID = '" + MerchID + '";
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20356360
UpdateString = "UPDATE [BCOMerchantTable] set [MerchName]= '" + NewMerchName +
 + "' , [MerchAddress]= '" + NewMerchAddress + "' WHERE MerchID = '" + MerchID + '";
0
 
LVL 11

Expert Comment

by:deroby
ID: 20356364
In other words : you can simply list all the fields to be updated one after the other, separated by comma's

UPDATE <sometable> SET field1 = 'value1', field2 = 'value2', field3 ='value3', etc...  WHERE <something is true>
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question