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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 optimize help

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-07-25 : 23:04:12

i have a table like
TBL_PARAM

PARAMETER_NAME VALUE
NEW1 10
NEW2 20
NEW3 30

and i need to use value like below

DECLARE @NEW1 NUMERIC(10), @NEW2 NUMERIC(10) , @NEW3 NUMERIC(10)

SELECT @NEW1 = VALUE FROM
TBL_PARAM where PARAMETER_NAME = 'NEW1'

SELECT @NEW2 = VALUE FROM
TBL_PARAM where PARAMETER_NAME = 'NEW2'

SELECT @NEW3 = VALUE FROM
TBL_PARAM where PARAMETER_NAME = 'NEW3'


and use the values for some calculation.


please suggest how can it be in one atatement and be optimize.


challenge everything

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-26 : 00:19:02
[code]
DECLARE @NEW1 NUMERIC(10), @NEW2 NUMERIC(10) , @NEW3 NUMERIC(10)

SELECT @NEW1 = MAX(CASE WHEN PARAMETER_NAME = 'NEW1' THEN VALUE END),
@NEW2 = MAX(CASE WHEN PARAMETER_NAME = 'NEW2' THEN VALUE END),
@NEW3 = MAX(CASE WHEN PARAMETER_NAME = 'NEW3' THEN VALUE END)
FROM TBL_PARAM
where PARAMETER_NAME IN ('NEW1','NEW2','NEW3')
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -