Click here to Skip to main content
14,639,649 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

In sql table i have column where value consists Quarterly or Null value.
I have written a StoreProcedure when passing parameters iam unable to get data of NULL Values.

What I have tried:

Hi,

In sql table i have column where value consists Quarterly or Null value.
I have written a StoreProcedure when passing parameters iam unable to get data of NULL Values.
Posted
Updated 23-Nov-17 18:07pm
Comments
Suvendu Shekhar Giri 23-Nov-17 5:36am
   
If your table has NULL values what data are you expecting to get?
Can you share the query?
krishnaraosan 23-Nov-17 6:06am
   
YES NULL VALUES ARE THERE .
I WANT QUERY WHEN VALUE IS NULL IT SHOULD SHOW AS mONTHLY or Quarterly in where condition to flter
Suvendu Shekhar Giri 23-Nov-17 6:35am
   
Can you share the query you are trying?
krishnaraosan 23-Nov-17 23:52pm
   
I have column name frequency where it consists value null and Quarterly

FREQUENCY--Column Name
NULL
Quarterly

Please find the query below.
I want to fetch records for both null value and quarterly.With the below query only null values records are fetched not quaterly

select * from MASTER
where FREQUENCY=(CASE WHEN FREQUENCY IS NULL THEN 'MONTHLY' ELSE 'Quarterly' END)
Suvendu Shekhar Giri 24-Nov-17 0:08am
   
Please check my solution if that is what you wanted to have-
My Solution[^]
krishnaraosan 24-Nov-17 0:13am
   
Iam using same query in the where condition it's not getting records for null values.I can fetch records when frequency is quarterly but not for null values.

select * from MASTER
where FREQUENCY=(CASE WHEN FREQUENCY IS NULL THEN 'MONTHLY' ELSE 'Quarterly' END)
Suvendu Shekhar Giri 24-Nov-17 0:16am
   
But why are you putting in WHERE condition?
It is not returning result because when Frequency will be NULL then your WHERE condition will evaluate to -
WHERE FREQUENCY='MONTHLY' which is false as you have FREQUENCY=NULL.
krishnaraosan 24-Nov-17 0:23am
   
SO HOW CAN I GET RECORDS FOR NULL VALUES AND QUARTERLY IN ONE QUERY
Suvendu Shekhar Giri 24-Nov-17 1:08am
   
Following query didn't work for you?
SELECT CASE WHEN FREQUENCY IS NULL THEN 'MONTHLY' ELSE 'Quarterly' END AS FREQ,* 
FROM MASTER
krishnaraosan 23-Nov-17 6:49am
   
I have column name frequency where it consists value null and Quarterly

FREQUENCY--Column Name
NULL
Quarterly

Please find the query below.
I want to fetch records for both null value and quarterly.With the below query only null values records are fetched not quaterly

select * from MASTER
where FREQUENCY=(CASE WHEN FREQUENCY IS NULL THEN 'MONTHLY' ELSE 'Quarterly' END)
Rate this:
Please Sign up or sign in to vote.

Solution 1

In SQL NULLs propagate - so if you add a column that contains a NULL, you will get NULL as the total result:
SELECT 1 + NULL + 2

So if you are performing any aggregate operation on your column, and a NULL value exists, you will get a NULL result.
One way round this is to use ISNULL in your query:
SELECT SUM(ISNULL(MyColumn, 0)) FROM MyTable
Will treat all NULL values in the column as zero.

If this isn't the problem you are having, then you need to explain in much better detail exactly what you problem is.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Based on the the query and details you have shared above, I believe you are looking to show "MONTHLY" and "QUARTERLY" in the frequency column of the result. If this is what you need then try following-
SELECT CASE WHEN FREQUENCY IS NULL THEN 'MONTHLY' ELSE 'Quarterly' END AS FREQ,* 
FROM MASTER


Please let me know if this is not what you wanted.

Thanks :)
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100