Replace the Null Value With Previous Which Is Not Null


declare @t table (names varchar(5))
INSERT INTO @t SELECT 'sam'
UNION ALL SELECT null
UNION ALL SELECT null
UNION ALL SELECT null
UNION ALL SELECT 'jac'
UNION ALL SELECT null
UNION ALL SELECT null  

SELECT names FROM @t

declare @str VARCHAR(5)
UPDATE @t
SET @str=COALESCE(names,@str)
,names=@str

SELECT names FROM @t

http://social.msdn.microsoft.com/Forums/en/transactsql/thread/9353f696-33fc-44c0-9dab-86b8b71ed40b
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s