SQL Query to Update a Target Table by Mapping with another Table in SQL Server
Suppose , we have a Target Table called 'Tbl_Customers', in which the columns [Cust_Segment] and [Bookings_Flag] are need to update by Mapping it with a another Table called 'Map_Table' . we can do it by using the Update query as follows..
With Inner Join :
With Inner Join :
UPDATE [Tbl_Customers]
SET [Cust_Segment] = M.[CustSegment],
[Bookings_Flag]= CASE When M.[Bookings_Type]='Product' Then 'Prod' ELSE 'Svc' END
From [Tbl_Customers] C Inner Join [Map_Table] M
On C.Cust_Id=M.CustId
With Where Clause :
SET [Cust_Segment] = M.[CustSegment],
[Bookings_Flag]= CASE When M.[Bookings_Type]='Product' Then 'Prod' ELSE 'Svc' END
From [Tbl_Customers] C Inner Join [Map_Table] M
On C.Cust_Id=M.CustId
With Where Clause :
UPDATE [Tbl_Customers]
SET [Cust_Segment] = M.[CustSegment],
[Bookings_Flag]= CASE When M.[Bookings_Type]='Product' Then 'Prod' ELSE 'Svc' END
From [Tbl_Customers] C, [Map_Table] M
Where C.Cust_Id=M.CustId
SET [Cust_Segment] = M.[CustSegment],
[Bookings_Flag]= CASE When M.[Bookings_Type]='Product' Then 'Prod' ELSE 'Svc' END
From [Tbl_Customers] C, [Map_Table] M
Where C.Cust_Id=M.CustId
--------------------------------------------------------------------------------------------------------
No comments:
Post a Comment
Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.