Need to place a condition on a select statement to determine which table to use in a query.

  • I am a newbie to sql. I am needing to show the vst_int_id's if the diag_ty='P' then use Table3 or if the diag_ty='S' then use Table4. I am not sure where to go from here to get the results that I need.

    SELECT Table1.vst_int_id, Table1.diag_ty, Table2.diag_ds,

    Table3.HtFcode, Table4.LVADcode

    FROM Table1 INNER JOIN

    Table2 ON Table1.diag_int_id = Table2. Diag_int_id INNER JOIN

    Table3.HtFcode ON Table2.diag_code = Table3.HtFcode INNER JOIN

    Table4.LVADcode ON

    Table2.diag_code = Table4.LVADcode

  • Look up the Case Statement in SQL's Books Online (the electronic manual). That should do as you need

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply