How to concatenate integer and varchars

  • Hi,

    We have a MSSQLServer 6.5 database...

    I want to select a varchar and integer field concatenated.. For this purpose I try to used cast and convert function.. Then I learned that these funtions are not avaliable for this version...

    Then How will concatenate different types in version 6.5

    Urgent help please....

     

     

     

  • I have no general help for convertions in 6.5, but I believe they had the str-function at that time. Worth a try, anyway:

    declare @my_int int

    select @my_int = 12

    select 'There are ' + str(@my_int) + ' in a year.'

  • SQL Server 6.5 does provide the CONVERT function. That function goes way back to early versions.

    Anyway, try this example:

    --drop table concatTest

    create table concatTest

    (

      cid int,

      myVarchar varchar(50),

      myInt int

    )

    SET NOCOUNT ON

    INSERT concatTest (cid, myVarchar, myInt) VALUES (1, 'First row = ', 1)

    INSERT concatTest (cid, myVarchar, myInt) VALUES (2, 'Second row = ', 2)

    INSERT concatTest (cid, myVarchar, myInt) VALUES (3, 'Third row = ', 3)

    SET NOCOUNT OFF

    SELECT myVarchar + CONVERT(varchar(10), myInt) as Concatenated, myVarchar, myInt

      FROM concatTest

     

  • To add on to what everyone else is saying....

    Remember you can not concatenate numbers. You can only concatenate strings. So you must convert numbers into string values.

    If you don't have CONVERT, 6.5 must have some other 'convert to string' command. Look through your documentation to find the command. All you need to do is convert the number to a string and then you can concatenate it with the rest of the string value(s).

    -SQLBill

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply