Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Bottom given qry to be converted.i hav selected qry in CASE is 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 RSRV .
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2008-09-09 : 04:58:06
Like this
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_AmountFROM RSRV ) AS T
MadhivananFailing to plan is Planning to fail
niranjankumark
Posting Yak Master
164 Posts
Posted - 2008-09-09 : 05:02:59
HOW WILL BE THE PERFORMANCE WHEN COMPARING THIS BOTH? CONSIDERING THIS KIND OF CALCULATION IN TABLE WILL IMPROVE ???
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2008-09-09 : 05:05:34
quote:Originally posted by niranjankumark HOW WILL BE THE PERFORMANCE WHEN COMPARING THIS BOTH? CONSIDERING THIS KIND OF CALCULATION IN TABLE WILL IMPROVE ???
I think the performance would be sameBut if you use derived table approach as I used, you have minimal code which is easy to understand and debugMadhivananFailing to plan is Planning to fail