Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
satheshjan 9-Apr-13 5:17am    
is there any common field for two tables
babli3 9-Apr-13 6:10am    
yes ,there is TierCode common in both
satheshjan 9-Apr-13 6:21am    
May be it ll correct...try
babli3 9-Apr-13 6:31am    
Thanks a lot but I am getting this error. Please help

System.Data.SqlClient.SqlException: Incorrect syntax near ','.

satheshjan 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.

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
Share this answer
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
Share this answer
babli3 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 9-Apr-13 7:52am    
i think it's not possible ...but i ll try to resolve and ll send u
babli3 9-Apr-13 7:58am    
Thank you so much for your help
satheshjan 9-Apr-13 8:00am    
its ok...No problem
DECLARE @MyTable TABLE (id int);
SET Table1.Name = 'Test'
WHERE T1.field = 'Your Value';
SET Table2.YourColumnName = 'Your Value'
FROM Table2
JOIN @MyTable m on =;

Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900