Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Error using getdate() in dynamic sql

Author  Topic 

rushdib
Yak Posting Veteran

93 Posts

Posted - 2004-03-12 : 09:56:55
declare @sql nvarchar(1000)

set @sql = 'select ' + getdate() + ''
exec sp_executesql @sql
print @sql

I am getting the following error:
Syntax error converting datetime from character string.

How do I fix this?

Thank you,

Rushdi

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-03-12 : 10:05:28
You need to use either CAST or CONVERT around the GETDATE to encase it within the string. for example

set @sql = 'select ' + convert(varchar(8), getdate(), 112) + ''
exec sp_executesql @sql
print @sql



Raymond
Go to Top of Page

rushdib
Yak Posting Veteran

93 Posts

Posted - 2004-03-12 : 12:08:53
That worked, thank you
Go to Top of Page
   

- Advertisement -