Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003
    Posts
    3

    Thumbs up Unanswered: How to concatenate an integer with char in a procedure

    How do I convert an integer to string using a stored procedure? Actually my problem is to concatenate two columns and inserts into a varchar column. The columns which are to be concatenated may be integer columns also.The CONCAT operator takes only strings as agument. How to do this?

    Any help is appreciated.

    Thanks

  2. #2
    Join Date
    Oct 2001
    Location
    Bangalore
    Posts
    186
    Hi,

    Do it this way.

    select VARCHAR(CAST(col1 AS CHAR)) || VARCHAR(CAST(col2 AS CHAR)) from tablename;

    The col1 and col2 columns are of integer type.

    Also this will truncate the integers with two digits to one digit, e.g. 10 will become 1.

    For this you can use:
    select VARCHAR(CAST(col1 AS CHAR(2))) || VARCHAR(CAST(col2 AS CHAR(2))) from tablename;

    So you should know the no.of digits in the integer columns.

    Cheers,
    Prashant

  3. #3
    Join Date
    Feb 2003
    Posts
    3
    Thanks a lot , it works.




    Originally posted by dahalkar_p
    Hi,

    Do it this way.

    select VARCHAR(CAST(col1 AS CHAR)) || VARCHAR(CAST(col2 AS CHAR)) from tablename;

    The col1 and col2 columns are of integer type.

    Also this will truncate the integers with two digits to one digit, e.g. 10 will become 1.

    For this you can use:
    select VARCHAR(CAST(col1 AS CHAR(2))) || VARCHAR(CAST(col2 AS CHAR(2))) from tablename;

    So you should know the no.of digits in the integer columns.

    Cheers,

Posting Permissions

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