Results 1 to 6 of 6

Thread: Concatenating

  1. #1
    Join Date
    Jan 2003
    Posts
    14

    Red face Unanswered: Concatenating

    I have a problem with string's concatenation...

    I want execute that...

    declare @colInt int
    exec('select * from ' + @server_name + ' where col1 = ' + @colInt)

    I'm traying this..

    exec('select * from ' + @server_name + ' where col1 = ' + convert(varchar, @colInt))

    but I can't

    Do you know how??

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Is @colInt storing something ? If so, just change the @colInt to a varchar(xx) - like this:

    declare @colInt varchar(10) -- pick a number that is correct for your use
    select @colInt = 12345
    exec('select * from ' + @server_name + ' where col1 = ' + @colInt)

  3. #3
    Join Date
    Jan 2003
    Posts
    14
    Yes, @colInt has an integer value..., and I can not change it...
    So, I would need other varchar variable and pass it the value of @colInt like varchar?

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    You do not need to change it - Treating your integer as a varchar is ok (sql server does an implicit conversion) - this will not affect your sql statement.

  5. #5
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249
    What do you store in @server_name ?

    Allowed table name format:

    Table1
    owner1.Table1
    Database1..Table1
    Database1.owner1.Table1
    Server1.Database1.owner1.Table1

  6. #6
    Join Date
    Jan 2003
    Posts
    14
    I have this...

    Server1.Database1.owner1.Table1

Posting Permissions

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