Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » SQL




 Page 1 of 1 [ 4 posts ] 



Author Message
 Post subject: CASE - QRY
 Post Posted: Sat Nov 21, 2009 2:12 pm 
Offline

Joined: Sat Feb 21, 2009 11:57 am
Posts: 40
this query need a conversion!!.i have selected qry in the CASE is

[code]
CASE WHEN RSRV.EFF_TS=@DT
THEN RSRV.GRS_RSRV_AMT
ELSE 0
END AS "Reserve Amount"

this same case is used in same select statement. can i use this case one time and refer for others without function.Need to avoid writing multiple times.another 2 places i have used this qry.


SELECT
CASE WHEN RSRV.EFF_TS=@DT
THEN RSRV.GRS_RSRV_AMT
ELSE 0
END AS "Reserve Amount",
RSRV.ACTUALAMOUNT,

( CASE WHEN RSRV.EFF_TS=@DT
THEN RSRV.GRS_RSRV_AMT
ELSE 0
/
RSRV.ACTUALAMOUNT )

/

(CASE WHEN RSRV.EFF_TS=@DT
THEN RSRV.GRS_RSRV_AMT
ELSE 0 )

FROM RSR

_________________
Login: yes
Password: i dont have one
password is incorrect

Login: yes
Password: incorrect


Top 
 Post subject: Re: CASE - QRY
 Post Posted: Sat Nov 21, 2009 2:12 pm 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
Like this

Code:
SELECT
   Reserve_Amount,
   RSRV.ACTUALAMOUNT,
   Reserve_Amount/   RSRV.ACTUALAMOUNT,
FROM
(
SELECT *,
   CASE WHEN RSRV.EFF_TS=@DT
   THEN RSRV.GRS_RSRV_AMT
   ELSE 0
   END AS Reserve_Amount
FROM RSRV
) AS T



Top 
 Post subject: Re: CASE - QRY
 Post Posted: Sat Nov 21, 2009 2:12 pm 
Offline

Joined: Sat Feb 21, 2009 1:08 pm
Posts: 549
HOW WILL BE da PERFORMANCE WHEN COMPARING dis BOTH? CONSIDERIN dis
KIND OF CALCULATION IN TABLE would IMPROVE ???


Top 
 Post subject: Re: CASE - QRY
 Post Posted: Sat Nov 21, 2009 2:13 pm 
Offline

Joined: Sat Feb 21, 2009 11:41 am
Posts: 45
I think da performance would be same
But if u use da derived tab approach as I used, you have a minimal
code which is easy 2 understand nd debug


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 4 posts ] 




Board index » Server Side Development » SQL


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron