SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to Write Maltiple quries in Case Statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dheresantosh9
Starting Member

India
3 Posts

Posted - 09/19/2013 :  02:41:11  Show Profile  Reply with Quote
HI Experts,

I have to do following scenario,

if 1st query Then 2nd Query
Else 'Msg'

How Can i do this using Case Statement??
Or can you please tell me how can do this by Other way??

Thank you.

santosh dhere

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 09/19/2013 :  02:47:49  Show Profile  Reply with Quote
we can use recursive/derived queries for that scenario..
Can you elaborate the scenario which you have with sample data and expected output

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/22/2013 :  02:42:11  Show Profile  Reply with Quote
whats it that you want to check from first query? a boolean result whether it returns row or value? if former use IF EXISTS otherwise use a variable to hold value and then use it in IF condition match

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 09/22/2013 :  12:19:34  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
You need to provide more information to help you.Explain what you are going to do with query1 and query2

Madhivanan

Failing to plan is Planning to fail

Edited by - madhivanan on 09/22/2013 12:21:02
Go to Top of Page

dheresantosh9
Starting Member

India
3 Posts

Posted - 09/25/2013 :  00:31:41  Show Profile  Reply with Quote
hi experts,

Thank you for replay. my question is,
if User is Manager then only balance of that vendor will checked,
i have done following query,

SELECT CASE
When (SELECT T0.USER_CODE='manager' FROM OUSR T0 WHERE INTERNAL_K = $[USER])
Then (SELECT CASE WHEN T0.[Balance] >= 0 AND T0.[Balance] <=10000 THEN 'Normal'
WHEN T0.[Balance] < 0 AND T0.[Balance] >-10000 THEN 'NORMAL'
WHEN T0.[Balance] > 10000 THEN 'High'
WHEN T0.[Balance] <-10000 THEN 'HIGH'
ELSE 'Returns'
FROM OCRD T0 WHERE T0.[CardCode] = $[$4.0.0] END)
ELSE 'RETURNS' END

if i run dis two query differently then it working fine.
How can i put it in one query.??
Thanks in advance.

santosh dhere
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/25/2013 :  07:47:47  Show Profile  Reply with Quote
Assuming you're using SQL Server

SELECT CASE
When OU.USER_CODE='manager' 
Then CASE WHEN T0.[Balance] >= 0 AND T0.[Balance] <=10000 THEN 'Normal'
          WHEN T0.[Balance] < 0 AND T0.[Balance] >-10000 THEN 'NORMAL'
          WHEN T0.[Balance] > 10000 THEN 'High'
          WHEN T0.[Balance] <-10000 THEN 'HIGH'
          ELSE 'Returns' 
     END
ELSE 'RETURNS' 
END
FROM OCRD T0 
INNER JOIN OUSR OU 
ON OU.USER = T0.INTERNAL_K
WHERE T0.[CardCode] = $[$4.0.0] )


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000