Solved

Combine SQL update strings

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

706 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

19 Experts available now in Live!

Get 1:1 Help Now