Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    6

    Unanswered: Boolean Calculated Fields in SQL Server

    Hi
    This may seem amazing and a stupid question but:

    Consider there is a parent table A and child table B and we want to write a query that has some fields from A and a calculated field which indicates whether A has any child record in B or not. The Value 1 means Yes and 0 means No. Has anybody an idea to write this in SQL Server?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select foo
         , bar
         , fap
         , case when exists
       ( select 1 from tableB
             where Afk = tableA.pk )
              then 1 else 0 end     as calcfield
      from tableA
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Posts
    6

    Thanks for your exact solution

    Originally posted by r937
    Code:
    select foo
         , bar
         , fap
         , case when exists
       ( select 1 from tableB
             where Afk = tableA.pk )
              then 1 else 0 end     as calcfield
      from tableA

Posting Permissions

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