Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

Stored procedure help:
SQL
SELECT l._application_id_c
   , p.ID, l.datetime_c
FROM dbo.leads l
    LEFT OUTER JOIN dbo.Applications p ON l.application_id_c = p.ApplicationID
WHERE (datetime_c IS NOT NULL)..

This is my stored proc. I want to do this if Datetime is null then i would pick the datetime from another table Applications ...I tried this ...I know i have done blunder..Please bear it and correct me.
SQL
WHERE (datetime_c IS NOT NULL)OR([datetime_c] IS NULL Then  [datetime_c]=p.[ApplicationDate])
Posted
v2

1 solution

You can use the COALESCE expression MSDN Coalesce[^]

eg
SQL
SELECT l._application_id_c, p.ID, COALESCE(l.datetime_c, p.ApplicationDate) as datetime_c
FROM dbo.leads l
    LEFT OUTER JOIN dbo.Applications p ON l.application_id_c = p.ApplicationID


[Edit - prompted by a comment from Prasad Khandekar I've given the full sql statement
 
Share this answer
 
v2
Comments
Maciej Los 5-Jun-13 9:11am    
+5
Prasad Khandekar 5-Jun-13 9:46am    
Hello Vidkaat,

In addition to above answer you may need to remove the datetime condition from your where clause.
CHill60 5-Jun-13 9:49am    
Good point - I've updated my solution. Thank you
vidkaat 5-Jun-13 10:12am    
It doesn't work...Can you suggest me something
vidkaat 5-Jun-13 10:17am    
I think you have misunderstood my question...I check if the datetime is null then i need to pick the value from applications table. When i tried the above it doesnot work

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900