SQL Server Performance

Recomended way to "concatenate" the bytes of integer values

Discussion in 'SQL Server 2008 General Developer Questions' started by EMoscosoCam, Sep 2, 2010.

  1. EMoscosoCam Member

    Hello
    Suppose that there is a table MyTable(col1 tinyint, col2 tinyint, col3 int, col4 bigint). What would be the most efficient way of updating col4 in such a way that it would be the result of "concatenating" col1 + col2 + col3?
    What I mean, is if col4 has 8 bytes, the value of col1 would occupy the third byte, col2 the fourth byte, and finally the last 4 bytes would correspond to col3.
    Thanks a lot.
  2. ashish287 New Member

    try this...update
    yourtable set col4 = cast(col1 as varchar(10))+ cast(col2 as varchar(10)) + cast(col3 as varchar(10))
    hope it give you expected result
  3. FrankKalis Moderator

    Ì would guess that the "most effective" way would be to have col4 as computed column concatenating col1 + col2 + col3.
    But I think you're not really looking for some kind of string concatenation at all, but rather some kind of bit manipulation. Can you please post an example of what you are looking for?
  4. Madhivanan Moderator

    [quote user="FrankKalis"]
    Ì would guess that the "most effective" way would be to have col4 as computed column concatenating col1 + col2 + col3.
    But I think you're not really looking for some kind of string concatenation at all, but rather some kind of bit manipulation. Can you please post an example of what you are looking for?
    [/quote]
    If any "Front end" is involved, it can be done there too

Share This Page