Overblog Follow this blog
Edit post Administration Create my blog
Balavardhan Reddy Narani

Bulk Update in Sqlserver

March 7 2009 , Written by Balavardhan Published on #SQL Server2005

Bulk Update in Sqlserver

Here by I am providing example how to update mutile columns by a single query

Table Structures

Employee Table
EmployeeID
First Name
Last Name
JobName
RoleID
Description
Status


Jobs Table
JobName
RoleID
Description

Roles Table
Role ID
Role Desc



Update Employee Table to Set RoleID of all Employees Based on there Job.

update a
set a.RoleID = b.RoleID
from Employee a
inner join
(
SELECT DISTINCT E.EmployeeID,S.RoleID
FROM Employee E
INNER JOIN dbo.Jobs S
ON E.JobName=S.JobName
) b
on a.EmployeeID = b.EmployeeID

Share this post

Repost 0

Comment on this post