Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6197
  • Last Modified:

t-sql - case when statment using null

hello, i am writing this query is sql server, and it's not executing, could someone please tell me Why, and how can i get to the solution, thanks :

i have 2 tables T1 and T2, and T2 contains less records, it's used to adjust some fields in T1 for reporting purposes, i cannot touch T1!


select T1.PK, T1.Date, T2,Date, case T2.Date when is null then T1.Date else T2.Date end
from T1 left outer join T2 on T1.PK = T2.PK
0
Nyana22
Asked:
Nyana22
3 Solutions
 
chapmandewCommented:
select T1.PK, T1.Date, T2,Date, case  when T2.Date is null then T1.Date else T2.Date end
from T1 left outer join T2 on T1.PK = T2.PK
0
 
cuziyqCommented:
Since you are just testing for NULL, then the ISNULL() function would serve you better.

select T1.PK, T1.Date, T2,Date, isnull(T2.Date,T1.Date)
from T1 left outer join T2 on T1.PK = T2.PK

That should do it.
0
 
BrandonGalderisiCommented:
This SHOULD work:

select T1.PK, T1.Date, T2,Date
  , case T2.Date when null then T1.Date else T2.Date end
from T1 left outer join T2 on T1.PK = T2.PK


This WILL work:

select T1.PK, T1.Date, T2,Date
  , case when T2.Date is null then T1.Date else T2.Date end
from T1 left outer join T2 on T1.PK = T2.PK
0
 
Nyana22Author Commented:
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now