Home Forums SQL Server 2008 T-SQL (SS2K8) how to write a column expression in a query based on other table value exist RE: how to write a column expression in a query based on other table value exist

  • Or you can use EXISTS:

    SELECT

    sno, sname, address,

    CASE

    WHEN EXISTS(SELECT 1 FROM dbo.StudentDrillEnrolled sde WHERE sde.sno = s.sno) THEN 'Y'

    WHEN EXISTS(SELECT 1 FROM dbo.StudentDrillNotEnrolled sdne WHERE sdne.sno = s.sno) THEN 'N'

    ELSE 'N/A'

    END AS Enrolled

    FROM dbo.student s

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.