-
SQL error
My query islike below.
SELECT DISTINCT CASE
WHEN esc.x1 = Substr(inp.y, 0, 3)
AND esc.x2 = Substr(inp.y, 4, 2)THEN esc.cc
WHEN esc.mcc = Substr(inp.y, 0, 3)
AND esc.mnc = Substr(inp.y, 4, 3)THEN esc.cc
END
FROM xxx inp,
yyy esc
WHERE CASE
WHEN esc.x1 IN( Substr(inp.y, 0, 3) )
AND esc.x2 IN( Substr(inp.y, 4, 2) )THEN esc.cc
WHEN esc.x1 IN( Substr(inp.y, 0, 3) )
AND esc.x2 IN( Substr(inp.y, 4, 3) )THEN esc.cc
END IS NOT NULL
Now the query is returning more than one row because it is satisfying both the case statement. what i want is if the case statement is NULL then only it should go for second one.Otherwise only the output of first case should be the output.Pls help me to modify the query accordingly.
Thnx in advance.
-
So... is the idea to return a row when either one of the two case conditions is true?
If that's the case I would use two case statements joined by OR.
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
SQL error
Hi thnx for your reply.
Can you put it in the query what ever you have explained as it would be helpful.
Thnx in advance.
-
Try this:
Code:
SELECT DISTINCT
CASE
WHEN esc.x1 IN (SUBSTR (inp.y, 0, 3))
AND esc.x2 IN (SUBSTR (inp.y, 4, 2), SUBSTR (inp.y, 4, 3))
THEN
esc.cc
ELSE NULL
END
FROM xxx inp, yyy esc
WHERE
CASE
WHEN esc.x1 IN (SUBSTR (inp.y, 0, 3))
AND esc.x2 IN (SUBSTR (inp.y, 4, 2), SUBSTR (inp.y, 4, 3))
THEN
esc.cc
ELSE NULL
END
IS NOT NULL;
"The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb
-
SQL Error
Thnx for your reply will try and let you know.
-
SQL error
Hi,
The above query also takes both the CASE statements.
Where as it should take only one case and if 1st case is NULL only then it should go for 2ns CASE
-
Originally Posted by wenowd
Where as it should take only one case and if 1st case is NULL only then it should go for 2ns CASE
As previously posted, use two case statements like...
CASE (condition 1)
OR
CASE (condition 2)
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
Originally Posted by wenowd
My query islike below.
SELECT DISTINCT CASE
WHEN esc.x1 = Substr(inp.y, 0, 3)
AND esc.x2 = Substr(inp.y, 4, 2)THEN esc.cc
WHEN esc.mcc = Substr(inp.y, 0, 3)
AND esc.mnc = Substr(inp.y, 4, 3)THEN esc.cc
END
FROM xxx inp,
yyy esc
WHERE CASE
WHEN esc.x1 IN( Substr(inp.y, 0, 3) )
AND esc.x2 IN( Substr(inp.y, 4, 2) )THEN esc.cc
WHEN esc.x1 IN( Substr(inp.y, 0, 3) )
AND esc.x2 IN( Substr(inp.y, 4, 3) )THEN esc.cc
END IS NOT NULL
Now the query is returning more than one row because it is satisfying both the case statement. what i want is if the case statement is NULL then only it should go for second one.Otherwise only the output of first case should be the output.Pls help me to modify the query accordingly.
Thnx in advance.
Please clarify, I am only seeing ONE case statement with two "WHEN" conditions.
What do you mean by: "what i want is if the case statement is NULL then only it should go for second one." which is the first and which is the second?
"The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb
-
Can you put those CASE statements with OR condition because i changed but still it going for both CASE statements.
Thnx in advanvce
-
Originally Posted by wenowd
Can you put those CASE statements with OR condition because i changed but still it going for both CASE statements.
Please show us what you did
Please remember to wrap code into code tags (#)
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|