Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Posts
    3

    Unanswered: HELP! Concatentation of 2 INT columns in SQL 2000

    I am looking to do a concatentation of 2 integer columns without converting them to varchar in SQL Server 2000. If you do a concatentation operator(+) on two integer columns it will try to do math instead of concatenation. Does anyone know how to do this without doing a cast or convert statement? I am asking due to performance issues.
    Here is the statement that I am trying to change:

    select
    cast(a.so_id as varchar ) + cast(a.line as varchar) cust_db_shipment_key,
    MULTIPLE OTHER PARTS OF THE STATEMENT

    from SO_LINE a left join SO b on a.SO_ID = b.SO_ID where carrier_id = '2' and cast(a.so_id as varchar) + cast(a.line as varchar) = ?

    Thanks for the help in advance!!!!!!!!
    Steve

  2. #2
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    There isn't too much of a performance hit for doing this in the SELECT. That FROM will kill you though. I would make it:
    SELECT
    CAST(a.so_id AS VARCHAR) + CAST(a.line AS VARCHAR) AS cust_db_shipment_key,
    blah,
    blah,
    blah
    FROM
    SO_LINE a
    LEFT JOIN SO b ON a.SO_ID = b.SO_ID
    WHERE
    carrier_id = '2'
    AND so_id = LEFT(@whatever,2) --However the string is broken down.
    AND a.line = RIGHT(@whatever,2)
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

  3. #3
    Join Date
    Jun 2004
    Posts
    3

    Thanks Derrick

    OK...I have come to the conclusion that I will not be keeping the columns as int's. The (@whatever, 2)...what is that representing?
    Thanks,
    Steve

  4. #4
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    ???? Whatever the "?" is in your post. I'm assuming your passing a string or something to this query aren't you?
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

  5. #5
    Join Date
    Jun 2004
    Posts
    3

    Talking Awesome!!!!!!!!!!!

    This works great so far. I am working off of a limited dataset so tomorrow will be the real test but so far so good.
    Thanks again,
    Steve

Posting Permissions

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