Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL
UPDATE Admin_Branch set BranchName=@BranchName where BranchCode=@BranchCode
 
UPDATE Admin_Tier set TierName=@TierName where TierCode=@TierCode
 

 
How can I join these two update statement into one.I want to use these in a gridview to update rows. thanks
Posted 9-Apr-13 0:03am
babli3793
Comments
satheshjan at 9-Apr-13 5:17am
   
is there any common field for two tables
Suman Agnihotri 3 at 9-Apr-13 6:10am
   
yes ,there is TierCode common in both
satheshjan at 9-Apr-13 6:21am
   
May be it ll correct...try
Suman Agnihotri 3 at 9-Apr-13 6:31am
   
Thanks a lot but I am getting this error. Please help
 
System.Data.SqlClient.SqlException: Incorrect syntax near ','.
 
Thanks
satheshjan at 9-Apr-13 6:35am
   
Try to copy the query from here and run it in SQL Server Management Studio. It will give you an idea on what syntax is incorrect.
Suman Agnihotri 3 at 9-Apr-13 6:39am
   
i did run on sql server the errror is on update a,b . Thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

update a,b set a.BranchName=@BranchName ,b.TierName=@TierName from Admin_Branch a inner join
Admin_Tier b on a.commonclunname=b.commonclunname where a.BranchCode=@BranchCode and b.TierCode=@TierCode
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

other wise u can do it in single qtype only
 
UPDATE Admin_Branch
SET a..BranchName=@BranchName
FROM Admin_Branch a, Admin_Tier b
WHERE a.BranchCode=@BranchCode
and b.TierCode=@TierCode
 
UPDATE Admin_Tier
SET b.TierName=@TierName
FROM Admin_Branch a, Admin_Tier b
WHERE a.BranchCode=@BranchCode
and b.TierCode=@TierCode
try this may be correct
  Permalink  
Comments
Suman Agnihotri 3 at 9-Apr-13 7:48am
   
I already tried the single querty and its working fine.
But problem is i am placing this update command in Gridview for updating rows
and i cant keep two update commands together .
so i wanted to join these two tables and update
satheshjan at 9-Apr-13 7:52am
   
i think it's not possible ...but i ll try to resolve and ll send u
Suman Agnihotri 3 at 9-Apr-13 7:58am
   
Thank you so much for your help
satheshjan at 9-Apr-13 8:00am
   
its ok...No problem
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

DECLARE @MyTable TABLE (id int);
BEGIN TRANSACTION
UPDATE Table1
SET Table1.Name = 'Test'
OUTPUT INSERTED.id INTO @MyTable
WHERE T1.field = 'Your Value';
UPDATE Table2
SET Table2.YourColumnName = 'Your Value'
FROM Table2
JOIN @MyTable m on m.id = Table2.id;

COMMIT;
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 319
1 Kornfeld Eliyahu Peter 265
2 Maciej Los 249
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 175
0 OriginalGriff 5,107
1 DamithSL 4,157
2 Maciej Los 3,595
3 Kornfeld Eliyahu Peter 3,450
4 Sergey Alexandrovich Kryukov 2,741


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100