convert | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive


Here is the query.. declare @amount as money
set @amount = (select sum(OffAmount)From OffBud where OffBud .budId = 5)
print @amount Am getting the follwing error: Server: Msg 257, Level 16, State 3, Line 6
Implicit conversion from data type money to nvarchar is not allowed. Use the CONVERT function to run this query.
Pls help Thanks!
"He laughs best who laughs last"
Print command only prints characters.
so if you fire:
print 5 –will error but
print ‘5’ –will print 5 in message pane. So consider this: declare @var1 int
set @var1=5 print @var1—will error
print convert(varchar(10),@var1) –will print the value of variable So if you print any number, you need to explicitly convert it into characters else it errors.
You really should avoid using the MONEY data type. Not only is it going to deprecate sooner or later, but it is also imprecise. Consider this example by Steve Kass
declare @m1 money, @m2 money, @m3 money
declare @d1 decimal(19,4), @d2 decimal(19,4), @d3 decimal(19,4)
set @m1 = 1.00
set @m2 = 345.00
set @m3 = @m1/@m2
set @d1 = 1.00
set @d2 = 345.00
set @d3 = @d1/@d2
select @m3, @d3 ——————— ———————
.0028 .0029 (1 row(s) affected) Both calculations are "correct" according to the specifications of the data types involved. However when you check this with Excel, you’ll find the result to be 0,002898551. So, the DECIMAL calculation is "more" correct, with the MONEY calculation being off with more than 3%. I guess in most environment such a difference is not acceptable.

Frank Kalis
Microsoft SQL Server MVP
Heute schon gebloggt?