Arrao4u

…a blog by Rama Rao

Archive for the ‘Using case statement in When update column in Sql Server’ Category

using case statement when update the column in sql server table

Posted by arrao4u on January 21, 2010

In my sql server table i have a scenerio that column name:

DesignedStartDate if it is null then update the column otherwise don’t update the column

if(@ProcessStatus=‘QC Query Close’ or @ProcessStatus=‘QC Query Open’ or @ProcessStatus

=‘QC-Finished’ or @ProcessStatus=‘QC-Rejected’)

Begin

–print ‘QC’

Update specart set ProcessStatus=@ProcessStatus,QCRemarks=@QCRemarks

,DesignedBy=(Case when DesignedBy is null then @UserName end)

,DesignedStartDate=(Case when DesignedStartDate is null then getdate()+0.52 else DesignedStartDate end), DesignedEndDate

=(Case when DesignedEndDate is null then getdate()+0.52 else DesignedEndDate end), PRName

=(Case when PRName is null then @UserName else PRName end), PREndDate

=(Case when PREndDate is null then getdate()+0.52 else PREndDate end), QCName

=@UserName,QCEndDate=getdate()+0.52, LastUpdatedBy

=@UserName,LastUpdatedDate=getdate()+0.52

where specArtnumber=@SpecArtNumber

End

Posted in Using case statement in When update column in Sql Server | Leave a Comment »