Need some help with single and double quotes.
I am trying to build a dynamic query but I can't get the quotes right around the date.
declare @mydate datetime
set @mydate=getdate()
declare @comp
set @comp='1st'
--Version 1
exec('UPDATE [MyDatebase].[dbo].[' + @comp + ' table]' +
' SET [BillingDate] = ' + char(39) +
CONVERT(VARCHAR(10), @mydate, 101) + char(39))
--Version 2
exec('UPDATE [MyDatebase].[dbo].[' + @comp + ' table]' +
' SET [BillingDate] = CONVERT(VARCHAR(10), @mydate, 101)))
This is what the final query should look like
UPDATE [MyDatabase].[dbo].[1st table] SET [BillingDate] = '04/26/2009'
Thanks
Simi
I am trying to build a dynamic query but I can't get the quotes right around the date.
declare @mydate datetime
set @mydate=getdate()
declare @comp
set @comp='1st'
--Version 1
exec('UPDATE [MyDatebase].[dbo].[' + @comp + ' table]' +
' SET [BillingDate] = ' + char(39) +
CONVERT(VARCHAR(10), @mydate, 101) + char(39))
--Version 2
exec('UPDATE [MyDatebase].[dbo].[' + @comp + ' table]' +
' SET [BillingDate] = CONVERT(VARCHAR(10), @mydate, 101)))
This is what the final query should look like
UPDATE [MyDatabase].[dbo].[1st table] SET [BillingDate] = '04/26/2009'
Thanks
Simi