• Sorry about that, my bad...I jumped too quick.

    Matt is correct with the 'char(39)'. I still could not get a similar construct to run in the 'exec' statement.

    I had to pull the sql out in to a separate variable, build the sql in it, then exec(@sql).

    declare @username varchar(30)

    select @username = 'AAATestUser'

    declare @sql varchar(1000)

    select @sql = 'select * from userstable where username = ' + char(39) + @username + char(39) -- (all of that on one row)

    exec(@sql)

    If I tried to do the exec and build the string at the same time I kept getting errors, running in Query Analyzer. I also checked an SP I wrote a some time ago that is very similar (dynamic sql) and I had constructed it in a variable and then exec(variable), so I probably ran into this before.

    One of those days.

    If it was easy, everybody would be doing it!;)