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.
Author |
Topic |
yesmein
Starting Member
1 Post |
Posted - 2009-04-17 : 17:43:29
|
Hello;I have the following tables and columns:Faci (Table); PNum (Column)FaciGrp (Table); PNum, GrID (Columns)Profile (Table): PNum, Criteria, Value (Columns)The content in the tables is as follows: Faci PNum 101 102 103 104 FaciGrp PNum GrID 101 2002101 2003 102 2002103 2004I need to transfer all the ProvNum in Facility table to Profile table and also group id's that have 2002 and put "Yes" or "No" in the values column. So my profile table would look likeProfilePNum Criteria Value101 2002 Yes102 2002 Yes103 2002 No104 2002 NoI am having trouble getting the sql that can do this. Can anyone please help?Thanks a lot. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-04-18 : 15:47:10
|
[code]INSERT INTO Profile (PNum, Criteria, Value)SELECT f.PNum,2002 AS Criteria,CASE WHEN fg.PNum IS NULL 'No' ELSE 'Yes' END AS ValueFROM Faci fLEFT JOIN FaciGrp fgON fg.PNum=f.PNumAND fg.GrID=2002--see the inserted rows backSELECT * FROM Profile[/code] |
 |
|
|
|
|