Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

Update column if previous value is NULL

$
0
0

Hi,

I need to update a column based on current row value and previous row value. IF both are not equal then i should make a update. ex: Name_Previous_Value : "Application" . Name_Current_Value : "Request" . In this case I am using the below code and updating,

IF  @Name_Previous_Value <>@Name_Current_Value

BEGIN

SET @myqry2='UPDATE SSDB_Railroad  SET Name = '+ ''''+@Name+'''' +' '+'WHERE Name =  ' + ''''+@Name1+''''
 EXECUTE sp_executesql @myqry2

END

In other scenario i have previous row value as NULL , Can i compare in a same way and update the current row based on previous row?  Below is the screenshot

Here RC2KEY column is NULL in previous row as well as current row . How do i update the current row? Pls help


Deepa


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>