Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
dheresantosh9
Starting Member
3 Posts |
Posted - 2013-09-19 : 02:41:11
|
HI Experts,I have to do following scenario,if 1st query Then 2nd QueryElse '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
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-09-19 : 02:47:49
|
we can use recursive/derived queries for that scenario..Can you elaborate the scenario which you have with sample data and expected output--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-09-22 : 02:42:11
|
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 MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-09-22 : 12:19:34
|
You need to provide more information to help you.Explain what you are going to do with query1 and query2MadhivananFailing to plan is Planning to fail |
|
|
dheresantosh9
Starting Member
3 Posts |
Posted - 2013-09-25 : 00:31:41
|
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 CASEWhen (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' ENDif i run dis two query differently then it working fine.How can i put it in one query.??Thanks in advance.santosh dhere |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-09-25 : 07:47:47
|
Assuming you're using SQL ServerSELECT CASEWhen 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' ENDELSE 'RETURNS' ENDFROM OCRD T0 INNER JOIN OUSR OU ON OU.USER = T0.INTERNAL_KWHERE T0.[CardCode] = $[$4.0.0] ) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|