SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Copy a Data in a Row then Insert to Another Row
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

leinad28
Starting Member

Philippines
4 Posts

Posted - 10/17/2012 :  10:06:51  Show Profile  Reply with Quote
Hi guys,

I'm stuck.Need some help about copying a data in a row then insert this data in another row when the field is blank or null. See sample data below:

MsgType ProcessCode Date TraceNumber InstCode
0200 480000 20121017 000001 9901
0210 480000 20121017 000001 NULL

I need only to copy the data on field InstCode then insert this in NULL row below.

I'm confused if what could be the best way to do it.
Will appreciate a lot for some inputs. Thanks

Edited by - leinad28 on 10/17/2012 10:10:51

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/17/2012 :  23:40:23  Show Profile  Reply with Quote

UPDATE t
SET t.InstCode = t1.InstCode 
FROM table t
INNER JOIN table t1
ON t1.ProcessCode = t.ProcessCode 
AND t1.Date = t.Date 
AND t1.TraceNumber = t.TraceNumber 
WHERE t1.InstCode IS NOT NULL
AND t.InstCode IS NULL


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000