Tuesday, March 20, 2012

Plz Help me out in this query

Declare @.i int
Select @.i=D_Places from MachineTests Where Test_Name='WBC_Count'
--Where D_Places is a user defined Number which defines the scale for
this Test
--While Converting it to Decimal

-- What does the following query do
-- I need to check the flag FORCE_HOLD_NDR if its 1 then
-- conversion is done on Result field of MachineResults Table

Select Case(FORCE_HOLD_NDR)
WHEN 1 THEN convert(DECIMAL(18,@.i), Result)
ELSE Result
END

Quote:

Originally Posted by

>From MachineResults


--Sounds really easy :) but its prompting me an Error
--"Server: Msg 170, Level 15, State 1, Line 5
--"Line 5: Incorrect syntax near '@.i'."

/*
So the problem i m facing is in supplying a variable (@.i in this case)
in Decimal constructor..

Is there any solution to remove this error however the bussiness
requiremt cant be
changed as the scale for the decimal is defined by the user in setup
file and it
can be anything ..

*/
Hope u guys Understand my question

Regards
Mohammad Rehan
Nortec Softwares Pvt LTDAm 17 Nov 2006 05:22:51 -0800 schrieb Roni:
...

Quote:

Originally Posted by

Select Case(FORCE_HOLD_NDR)
WHEN 1 THEN convert(DECIMAL(18,@.i), Result)
ELSE Result
END

Quote:

Originally Posted by

>>From MachineResults


>
--Sounds really easy :) but its prompting me an Error
--"Server: Msg 170, Level 15, State 1, Line 5
--"Line 5: Incorrect syntax near '@.i'."
>


This is not possible, you have to build a string and then execute this
string using EXECUTE or sp_executesql.
Here is an excellent article about it:
http://www.sommarskog.se/dynamic_sql.html
bye,
Helmut

No comments:

Post a Comment