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
 declare un-static decimal value

Author  Topic 

issammansour
Yak Posting Veteran

51 Posts

Posted - 2007-10-12 : 09:00:20
I try to declare a variable with un static decimal point in the following statement:-

declare @mpt int;
declare @mpq nvarchar (1)
SELECT @mpq = (SELECT mpq FROM ims.parm)

exec('declare @MM1 decimal (10,'+ @mpq +');')

set @mm1 = 1
print @mpt
when i print the declare statement looks like the following:
declare @MM1 decimal (10,2);
but with exec the statement, I have the following error:-
Msg 137, Level 15, State 1, Line 18
Must declare the scalar variable "@mm1".

Best regards

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-12 : 09:23:48
This is at least the second time you fiddle around with dynamic sql, when you don't have to!
Please read http://www.sommarskog.se/dynamic_sql.html before posting any question again regarding dynamic sql.
Especially the part regarding SCOPE on http://www.sommarskog.se/dynamic_sql.html



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-10-12 : 09:31:59
>> I try to declare a variable with un static decimal point ...

Why the heck are you doing this? For formatting? Don't format data in SQL, just return it and let your client format it. If it is for mathematical purposes, just use decimals at the highest precision that you need, and round the results to a lower precision (where necessary) using basic math.

If you can be more specific about what you are trying to do, we can certainly give you better ways to do it rather than what you are trying. You are making something probably quite simple extremely convoluted and complicated...

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -