Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2011
    Posts
    6

    Unanswered: How to use multiple Cases in Sql

    Hi,
    Im using Sql server 2005,I have two tables.Say table1 and table2
    All the data is fetched from Table1 only.table two is used for confirmation.
    Like There is a Column say StudentMobile in table2 which hold the values either True or False.table 2 also has a Registration Number Column,now if this StudentMobile value is true then only the data of that particular student should be fetched from Table1.
    Please Have a look at my Query.I have successfully done with using single Case Statement but m not able to aplly multiple Cases.
    Please Guide.

    Code:
    SELECT Table1.RegNo,Table1.MobileNo,
    case when Table2.UseStudentMobile='True' then Table1.StudentMobile
    end 
    //Im having issue when i use another Case Here
    case when Table2.ParentStudentMobile='True' then Table1.ParentMobile
    end 
    
    FROM Table1 INNER JOIN
    Table2 ON Table1.RegNo = Table2.Regno
    The code in Bold is the Line that is giving me Error.If i remove that case than im not getting any error.

  2. #2
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    Select Table1.RegNo,
    Table1.MobileNo,
    Case When Table2.UseStudentMobile = 'True'
    Then Table1.StudentMobile
    Else Case when Table2.ParentStudentMobile='True'
    Then Table1.ParentMobile
    End
    End
    FROM Table1
    INNER JOIN Table2
    ON Table1.RegNo = Table2.Regno

    try this query
    Cheers....

    baburajv

  3. #3
    Join Date
    Sep 2011
    Posts
    6

    Correct Query

    Thanks frnds for the reply.
    Its working great
    Thank You.

Tags for this Thread

Posting Permissions

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