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.
| Author |
Topic |
|
dbist
Yak Posting Veteran
52 Posts |
Posted - 2008-05-06 : 15:36:50
|
| why can't I do this?declare @stamp nvarchar(25)declare @sql nvarchar(25)set @stamp = 'select current_timestamp'set @sql = exec(@stamp)what can I do to achieve what I need to do? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-06 : 15:42:41
|
| Why are you using dynamic SQL?declare @dt datetimeselect @dt = current_timestampTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
dbist
Yak Posting Veteran
52 Posts |
Posted - 2008-05-06 : 16:00:52
|
| I am trying to return the timestamp and use it in the following backup statement to dynamically append timestamp to backup file name. So I do need @sql to store the current time. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sanoj_av
Posting Yak Master
118 Posts |
Posted - 2008-05-09 : 06:52:45
|
Well.you need not use Dyanamic SQL for this. However you can use it as follows incase you want to use it for some other reason.declare @stamp nvarchar(50)declare @sql nvarchar(25)Declare @Param nvarchar(25)set @param= N'@nsql varchar(25) output'set @stamp = 'select @nsql=current_timestamp'exec sp_executesql @stamp,@param,@nsql=@sql outputselect @sqlquote: Originally posted by tkizer You do not need to use dynamic SQL to append a timestamp to the filename in the backup command.Check out my backup code to see:http://weblogs.sqlteam.com/tarad/archive/2007/02/26/60120.aspxTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
|
 |
|
|
|
|
|