Solved

Combine SQL update strings

Posted on 2007-11-27
3
911 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

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.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now