Results 1 to 2 of 2

Thread: Help with SQL query

  1. #1
    Join Date
    Apr 2009
    Posts
    8

    Help with SQL query

    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 2002
    101 2003
    102 2002
    103 2004

    I need to transfer all the PNum in Faci table to Profile table and also grid's (which are called criteria in Profile table) that have 2002 and put "Yes" or "No" in the values column. So my profile table would look like

    Profile
    PNum Criteria Value
    101 2002 Yes
    102 2002 Yes
    103 2002 No
    104 2002 No

    I am having trouble getting the sql that can do this. Can anyone please help?

    Thanks a lot.

  2. #2
    Join Date
    Feb 2009
    Posts
    1
    Hello,

    Try this

    Code:
    SELECT A.PNum, 2002 AS GID , MAX(CASE WHEN B.GRID = 2002 THEN 'Yes' ELSE 'No' END) AS Val
    FROM [dbo].[A] AS A
    FULL JOIN [dbo].[B] AS B
    ON A.PNum = B.PNum
    GROUP BY A.PNum
    ORDER BY A.PNum
    Hope helpful...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •