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
 Programming with monetary data ...

Author  Topic 

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 2008-05-03 : 07:39:33
Hi
Could anyone tell me why i get Error when i execute the following code:
----------------------
declare @a money
set @a=121.23
print @a

Server: Msg 257, Level 16, State 3, Line 5
Implicit conversion from data type money to nvarchar is not allowed. Use the CONVERT function to run this query.
---------------------------------------------
isn't that , money data are like integer data? so why i should use type casting?

By the way is it necessary to use currency symbol when we are working with monetary data or not?

Thank.
Kind Regards.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-03 : 07:40:50
Nope as error suggests you need to use CONVERT function for conversion.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-03 : 08:53:15
quote:
Originally posted by ZarrinPour

Hi
Could anyone tell me why i get Error when i execute the following code:
----------------------
declare @a money
set @a=121.23
print @a

Server: Msg 257, Level 16, State 3, Line 5
Implicit conversion from data type money to nvarchar is not allowed. Use the CONVERT function to run this query.
---------------------------------------------
isn't that , money data are like integer data? so why i should use type casting?

By the way is it necessary to use currency symbol when we are working with monetary data or not?

Thank.
Kind Regards.



I dont get an error for this code
Are you sure you posted the entire script?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-05-03 : 09:15:43
It's not the fact that you were trying to PRINT a money datatype variable, but most likely you were trying to print the CONCATENATION of a money variable with a varchar variable (or constant). Like perhaps a dollar sign

Be One with the Optimizer
TG
Go to Top of Page

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 2008-05-03 : 13:53:48
quote:

I dont get an error for this code
Are you sure you posted the entire script?




Hi
Believe it or not , i'm running the following code

declare @a money
set @a=121.23
print @a


in the query Analizer (Sql server 2000) and i receive the above error.

Thanks.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-03 : 14:06:48
How about this?

declare @a money
set @a=121.23
print CONVERT(varchar(10),@a)


I think PRINT ststement is trying to implicitly convert money value to varchar which is causing this error. The data type of variable passed to PRINT statement should be character (char,varchar,...).
Go to Top of Page

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 2008-05-03 : 15:31:57
quote:
Originally posted by visakh16

How about this?

declare @a money
set @a=121.23
print CONVERT(varchar(10),@a)


I think PRINT ststement is trying to implicitly convert money value to varchar which is causing this error. The data type of variable passed to PRINT statement should be character (char,varchar,...).



Thank you visakh16
I got my answer.
By the way is it necessary to use currency symbol when we are working with monetary data or not? i didn't see any major difference
between whether using currency sign or not using it.is there any poin here?

Kind Regards.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-03 : 15:52:49
quote:
Originally posted by ZarrinPour

quote:
Originally posted by visakh16

How about this?

declare @a money
set @a=121.23
print CONVERT(varchar(10),@a)


I think PRINT ststement is trying to implicitly convert money value to varchar which is causing this error. The data type of variable passed to PRINT statement should be character (char,varchar,...).




Thank you visakh16
I got my answer.
By the way is it necessary to use currency symbol when we are working with monetary data or not? i didn't see any major difference
between whether using currency sign or not using it.is there any poin here?

Kind Regards.




Not necessary. The formatting will be usually done on front end application to show the currency sin.
Go to Top of Page
   

- Advertisement -