Solved

Combine SQL update strings

Posted on 2007-11-27
3
923 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Batch & SQLCMD & SQL: execute maintenance plan outside sql 13 51
How to keep a record with the highest value 3 38
Need time in SQL 8 30
Many to one in one row 2 36
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

740 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