| Author |
Topic |
|
ZarrinPour
Yak Posting Veteran
66 Posts |
Posted - 2008-05-03 : 07:39:33
|
| HiCould anyone tell me why i get Error when i execute the following code:----------------------declare @a moneyset @a=121.23print @aServer: Msg 257, Level 16, State 3, Line 5Implicit 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. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-05-03 : 08:53:15
|
quote: Originally posted by ZarrinPour HiCould anyone tell me why i get Error when i execute the following code:----------------------declare @a moneyset @a=121.23print @aServer: Msg 257, Level 16, State 3, Line 5Implicit 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 codeAre you sure you posted the entire script?MadhivananFailing to plan is Planning to fail |
 |
|
|
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 OptimizerTG |
 |
|
|
ZarrinPour
Yak Posting Veteran
66 Posts |
Posted - 2008-05-03 : 13:53:48
|
quote: I dont get an error for this codeAre you sure you posted the entire script?
HiBelieve it or not , i'm running the following code declare @a moneyset @a=121.23print @ain the query Analizer (Sql server 2000) and i receive the above error.Thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-03 : 14:06:48
|
How about this?declare @a moneyset @a=121.23print 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,...). |
 |
|
|
ZarrinPour
Yak Posting Veteran
66 Posts |
Posted - 2008-05-03 : 15:31:57
|
quote: Originally posted by visakh16 How about this?declare @a moneyset @a=121.23print 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 visakh16I 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 differencebetween whether using currency sign or not using it.is there any poin here?Kind Regards. |
 |
|
|
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 moneyset @a=121.23print 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 visakh16I 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 differencebetween 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. |
 |
|
|
|