case statement only on column that is not null
By : Constantin Vrabie
Date : March 29 2020, 07:55 AM
wish of those help I'm writing a query that searches for people over 18 based on their birthdate and the current date. There are some instances where a person does not have a birth date in the database. For these people I just want to include them in my query and not perform the where clause on them. Is this possible? This is a db2 database , Instead of a CASE just use OR: code :
select *
from people i
where (coalesce(i.birth_date) != '' AND (i.birth_date < (SELECT CURRENT_DATE - 18 years from datetoday)))
OR coalesce(i.birth_date) = ''
|
Can you change the value of a column that is NULL using a CASE?
By : J. Rothwell
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You can certainly use the is [not] null predicate like so: code :
select
case
when t.Column1 is null then '1/1/2001'
else t.Column1
end
,t.Column2
from Table1 as t
select
isnull(t.Column1, '1/1/2001')
,t.Column2
from Table1 as t
select
coalesce(t.Column1, '1/1/2001')
,t.Column2
from Table1 as t
|
SQL Case Statement NULL column
By : mvatlarge
Date : March 29 2020, 07:55 AM
wish help you to fix your issue It looks like you can use COALESCE to achieve your goal without an explicit conditional: code :
SELECT *,
(Total_Retail_Price - (Total_Retail_Price * COALESCE(Discount, 0))) * Quantity AS Rev
FROM DATA.Cumulative_Profit_2013 AS P
|
Why sql case is not working on null condition of int column
By : Hugo Aguilar
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have used SQL CASE statement on an INT type of column of a table. Following is the SQL table schema and query which is working fine. , try: code :
SELECT T.ID,T.ACCEPTED,
(CASE WHEN T.ACCEPTED IS NULL THEN 'NOT ACCEPTED' END) AS STATUS
FROM #TEMP_A T
|
TSQL: CASE if one column of a row is NULL every other column will be set NULL depending on another row
By : user2277984
Date : March 29 2020, 07:55 AM
like below fixes the issue this is my first question on stackoverflow so sorry if its not that understandable. I don't know if this is even possible. , You can apply a Windowed Aggregate: code :
SELECT MONTH,
case when -- any of the rows for a filial for a NULL
min(case when Like_for_like_sales is null then 0 end)
over (partition by Filial_number) = 0
then null
else Like_for_like_sales
end,
Filial_number,
Sales,
PreviousYear_Sales
FROM test
ORDER BY Filial_number,
MONTH
|