mattpayne59
asked on
SQL Query Help
I have a really massive SQL query that I use to run an export from one CRM into another CRM package. I just uncovered a problem with my query and I am not sure how to fix it. My basic syntax is this:
With C1 As
(
Select statement
),
C2 As
(
Select statement
)
select c1.value, C2.value
from C1
left join c2
I have 17 different joins here because this query is huge. Here is my question. One of the select queries in the top part of the statement is returning a null value sometimes. When it returns a null I need to run a different query to produce the correct values. I always have trouble creating programming logic in SQL but I basically want:
if query = NULL then query2.
Can anyone make any sense of this and tell me how I can accomplish this? I am running in MS SQL 2008.
Thank you!
With C1 As
(
Select statement
),
C2 As
(
Select statement
)
select c1.value, C2.value
from C1
left join c2
I have 17 different joins here because this query is huge. Here is my question. One of the select queries in the top part of the statement is returning a null value sometimes. When it returns a null I need to run a different query to produce the correct values. I always have trouble creating programming logic in SQL but I basically want:
if query = NULL then query2.
Can anyone make any sense of this and tell me how I can accomplish this? I am running in MS SQL 2008.
Thank you!
You need to use ISNULL and CASE in your statements.
ASKER
Ok but how do I structure it because I dont know if I need the other case until after I complete the select query?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.