Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help with query.

Author  Topic 

chapo
Starting Member

39 Posts

Posted - 2008-05-20 : 11:54:59
What I'm trying to do is update the blank records of the Finish field with the one main record that stores the Finish code.

sample data
project|dwg|mark|finish|quan|date|type|main
07-324|B1210|B1210|GAL|2|2/29/2008|W|TRUE
07-324|B1210|1393||1|2/29/2008|L|FALSE
07-324|B1210|1393||1|null|L|FALSE
07-324|B1210|2010||3|2/29/2008|W|FALSE
07-324|B1210|2011||2|2/29/2008|L|FALSE
07-324|B1210|fb0994|F|1|2/29/2008|HS|FALSE
07-324|A1100|A1100|1|7|2/28/2008|W|TRUE
07-324|A1100|20||2|2/28/2008|PL|FALSE

would like
project|dwg|mark|finish|quan|date|type|main
07-324|B1210|B1210|GAL|2|2/29/2008|W|TRUE
07-324|B1210|1393|GAL|1|2/29/2008|L|FALSE
07-324|B1210|1393|GAL|1|null|L|FALSE
07-324|B1210|2010|GAL|3|2/29/2008|W|FALSE
07-324|B1210|2011|GAL|2|2/29/2008|L|FALSE
07-324|B1210|fb0994|F|1|2/29/2008|HS|FALSE
07-324|A1100|A1100|1|7|2/28/2008|W|TRUE
07-324|A1100|20|1|2|2/28/2008|PL|FALSE

The best way I thinck is for the records that the finihs is blank grab the dwg value and where it matches the mark value grab the finish from that one record and applied it to all matches. I have to update thousands of records for different projects so any help would be helpfull.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-20 : 12:05:18
[code]UPDATE t1
SET t1.finish=t2.finish
FROM (SELECT * FROM YourTable WHERE ISNULL(finish,'') = '')t1
INNER JOIN (SELECT * FROM YourTable WHERE ISNULL(finish,'') <> '')t2
ON t2.project=t1.project
AND t2.dwg=t1.dwg
[/code]

I'm assuming you will always have only a single record for each project,dwg combination with a valid value for finish and rest all will be blank.
Go to Top of Page
   

- Advertisement -