Results 1 to 3 of 3

Thread: Convert function

  1. #1
    Anastasia Guest

    Convert function

    Hi,
    Here is the statement I'm trying to run....

    declare @A varchar(5)
    select @A='123'
    select @A=(select convert(money,@A))
    select @A

    This is the error message I get:
    Implicit conversion from data type money to varchar is not allowed. Use the CONVERT function to run this query.

    Does anyone know what should I change in the query to make it work?

    Thank you very much,
    Anastasia.

  2. #2
    Duncan Maddox Guest

    Convert function (reply)


    -- This Returns 123.0
    -- Change the DECLARE to varchar(6) to return 123.00

    declare @A varchar(5)
    select @A='123'
    select @A = convert( varchar(10), convert(money,@A))
    select @A

    The problem is that you have defined @a as a varchar and you need to explicitly convert the result from a money type back to a varchar. Also value will be at least 6 characters long so converting to a varchar(5) wont work. In addition to that you dont need the extra SELECT you had in your original script.

    Hope this helps

    duncan

    PS But you could always just SELECT @a=@a+'.00'

    ------------
    Anastasia at 11/15/00 11:23:21 PM

    Hi,
    Here is the statement I'm trying to run....

    declare @A varchar(5)
    select @A='123'
    select @A=(select convert(money,@A))
    select @A

    This is the error message I get:
    Implicit conversion from data type money to varchar is not allowed. Use the CONVERT function to run this query.

    Does anyone know what should I change in the query to make it work?

    Thank you very much,
    Anastasia.

  3. #3
    eab Guest

    Convert function (reply)

    Im not sure exactly what you are trying to do with this but try

    declare @A varchar(10)
    select @A='123'
    select @A=convert(varchar(10),convert(money,@A))
    select @A


    OR


    declare @A varchar(5)
    declare @Am money
    select @A='123'
    select @Am= convert(money,@A)
    select @Am



    ------------
    Anastasia at 11/15/00 11:23:21 PM

    Hi,
    Here is the statement I'm trying to run....

    declare @A varchar(5)
    select @A='123'
    select @A=(select convert(money,@A))
    select @A

    This is the error message I get:
    Implicit conversion from data type money to varchar is not allowed. Use the CONVERT function to run this query.

    Does anyone know what should I change in the query to make it work?

    Thank you very much,
    Anastasia.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •