473,395 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Summary View Using CASE is only returning first row?

2
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_TblToFunctionalLocationMaster) >= '0') THEN 'NN_TblToFunctionalLocationMaster'
WHEN((SELECT COUNT(1) AS A FROM OI_TblToFunctionalLocationMaster) >= '0') THEN 'OI_TblToFunctionalLocationMaster'
WHEN((SELECT COUNT(1) AS A FROM SD_TblToFunctionalLocationMaster) >= '0') THEN 'SD_TblToFunctionalLocationMaster'
WHEN((SELECT COUNT(1) AS A FROM SS_TblToFunctionalLocationMaster) >= '0') THEN 'SS_TblToFunctionalLocationMaster'
ELSE NULL
END
Jul 11 '07 #1
2 1736
The CASE statement will only execute the first WHEN expression that evaluates to True & generally assumes that the WHEN expressions are mutually exclusive.

Eg

Expand|Select|Wrap|Line Numbers
  1.  
  2. CASE
  3. WHEN (Value < 0) THEN 'Neg'
  4. WHEN (Value = 0) THEN 'Zero'
  5. WHEN (Value > 0) THEN 'Pos'
  6. ELSE 'Undefined'
  7. END
  8.  
  9.  
You are using SELECT COUNT(1) From different tables (NN_TblToFunctionalLocationMaster, OI_TblToFunctionalLocationMaster etc)

You'll need to have a separate CASE statement for each.
Jul 11 '07 #2
KIDDLE
2
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
Jul 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.