TysonLPrice
Programmer
I'm having trouble putting quotes into a quoted string. This is what I want to do inside an execute statement:
IF (object_id('tempdb..##tb1_uga') IS not Null)
DROP TABLE ##tb1_uga
But dynamically adding a suffix of user name to it.
What I have is:
I thought ''' translated to a single quote but I keep getting sysntax errors running the execute.
The end result should be:
IF (object_id('tempdb..##tb1_uga') IS not Null)
DROP TABLE ##tb1_uga
But dynamically adding a suffix of user name to it.
What I have is:
Code:
declare @TableSuffix varchar(20)
set @TableSuffix = (select replace(system_user,'scmsna\','')) -- results in TPrice
declare @mytable varchar(30)
select @mytable = '##tb1_uga' + @tableSuffix
execute ('''IF (object_id(''tempdb..''' + @mytable + ''') IS not Null)
DROP TABLE ##tb1_uga''' + @mytable + ''')
I thought ''' translated to a single quote but I keep getting sysntax errors running the execute.
The end result should be:
Code:
Execute('IF (object_id('tempdb..##tb1_ugaTPrice') IS not Null) DROP TABLE ##tb1_ugaTprice')