Summary View Using CASE is only returning first row?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KIDDLE
    New Member
    • Jul 2007
    • 2

    Summary View Using CASE is only returning first row?

    Experts,

    Please help, I am trying to write a view that enables a list to be produced where other views in the database have a count > 0 ... but when I run this I only get a result returned for the first WHEN statement, the others are not returned, even though they have a count > 0 ?? Help please ... suggestions on approach if I am coming at this the wrong way.
    Thanks in Advance
    SELECT 'VIEWS TO BE CHECKED' =
    CASE
    WHEN((SELECT COUNT(1) AS A FROM NN_TblToFunctio nalLocationMast er) >= '0') THEN 'NN_TblToFuncti onalLocationMas ter'
    WHEN((SELECT COUNT(1) AS A FROM OI_TblToFunctio nalLocationMast er) >= '0') THEN 'OI_TblToFuncti onalLocationMas ter'
    WHEN((SELECT COUNT(1) AS A FROM SD_TblToFunctio nalLocationMast er) >= '0') THEN 'SD_TblToFuncti onalLocationMas ter'
    WHEN((SELECT COUNT(1) AS A FROM SS_TblToFunctio nalLocationMast er) >= '0') THEN 'SS_TblToFuncti onalLocationMas ter'
    ELSE NULL
    END
  • SkinHead
    New Member
    • Jun 2007
    • 39

    #2
    The CASE statement will only execute the first WHEN expression that evaluates to True & generally assumes that the WHEN expressions are mutually exclusive.

    Eg

    Code:
    CASE
    WHEN (Value < 0) THEN 'Neg'
    WHEN (Value = 0) THEN 'Zero'
    WHEN (Value > 0) THEN 'Pos'
    ELSE 'Undefined'
    END
    You are using SELECT COUNT(1) From different tables (NN_TblToFuncti onalLocationMas ter, OI_TblToFunctio nalLocationMast er etc)

    You'll need to have a separate CASE statement for each.

    Comment

    • KIDDLE
      New Member
      • Jul 2007
      • 2

      #3
      Thanks for the reply, ended up going a complete new route to this ... Stored Procedure to return the results and then another to pull out the duplicate, changed and identical data across the two databases.

      Cheers
      Kiddle

      Comment

      Working...