Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    42

    Angry Unanswered: Problem of data type convertion

    I have field(id) having char(20) withvalue '0012'.I want to convert to int.

    I use the convert function convert(id,int) then it gave following error

    Implicit conversion from datatype 'INT' to 'CHAR' is not allowed. Use the CONVERT function to run this query

    Please help me

    Regards
    Bala M

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    The correct syntax is:
    convert (datatype, expression, [style])
    i.e.
    convert(int,id)

  3. #3
    Join Date
    Sep 2005
    Posts
    42
    oops.It was my typing mistake.But the error is comming the same.

    What has to be done

    Regards
    Bala

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    You say you want to convert from char to int
    But the error say you want to convert from int to char
    And I am unable to recreate your problem as you describe it
    Code:
    1> create table #t1 (id char(20))
    2> go
    1> insert into #t1 values ('0012')
    2> go
    (1 row affected)
    1> select convert(int,id) from #t1
    2> go
                 
     ----------- 
              12 
    
    (1 row affected)

Posting Permissions

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