In Windows, I have a folder, lets say 'ABC'. I'd like this folder to be
renamed only a daily basis, based the current datestamp, through T-SQL. So
far, I've come up the following T-SQL stmt:
SELECT RTRIM(LEFT(DATENAME(month, getdate()),3)+DATENAME(day,
getdate())+DATENAME(year, getdate()))
...How would I be able to implement the result of the above stament (in the
case, Feb232006) to be the new folder name, i.e., take the result of the SQL
select stmt. and pass it to the OS to rename a folder?
Thanks.DECLARE @.cmd VARCHAR(255);
SET @.cmd = 'ren "d:\abc\" "foo"';
EXEC master..xp_cmdshell @.cmd, NO_OUTPUT;
"Rob" <Rob@.discussions.microsoft.com> wrote in message
news:D2B570A3-A31A-4C80-A5E2-44ABD38E52BE@.microsoft.com...
> In Windows, I have a folder, lets say 'ABC'. I'd like this folder to be
> renamed only a daily basis, based the current datestamp, through T-SQL. So
> far, I've come up the following T-SQL stmt:
> SELECT RTRIM(LEFT(DATENAME(month, getdate()),3)+DATENAME(day,
> getdate())+DATENAME(year, getdate()))
> ...How would I be able to implement the result of the above stament (in
> the
> case, Feb232006) to be the new folder name, i.e., take the result of the
> SQL
> select stmt. and pass it to the OS to rename a folder?
> Thanks.|||"Rob" <Rob@.discussions.microsoft.com> wrote in message
news:D2B570A3-A31A-4C80-A5E2-44ABD38E52BE@.microsoft.com...
> In Windows, I have a folder, lets say 'ABC'. I'd like this folder to be
> renamed only a daily basis, based the current datestamp, through T-SQL. So
> far, I've come up the following T-SQL stmt:
> SELECT RTRIM(LEFT(DATENAME(month, getdate()),3)+DATENAME(day,
> getdate())+DATENAME(year, getdate()))
> ...How would I be able to implement the result of the above stament (in
> the
> case, Feb232006) to be the new folder name, i.e., take the result of the
> SQL
> select stmt. and pass it to the OS to rename a folder?
> Thanks.
Lookup xp_cmdshell in Books Online. Why do it in SQL though?
Your naming convention for folders looks very inconvenient. The user will
see the months sorted alphabetically in Explorer instead of chronologically.
The years will be mixed up too! Better to do:
\2006_02_23
\2006_02_24
\... etc
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||It's okay... I figured it out myself by using the following code:
declare @.date varchar(10)
declare @.cmd varchar(250)
set @.date = RTRIM(LEFT(DATENAME(month, getdate()),3)+DATENAME(day,
getdate())+DATENAME(year, getdate()))
Print @.date
set @.cmd = 'REN X:\ABC ' + @.date
Print @.cmd
"Rob" wrote:
> In Windows, I have a folder, lets say 'ABC'. I'd like this folder to be
> renamed only a daily basis, based the current datestamp, through T-SQL. So
> far, I've come up the following T-SQL stmt:
> SELECT RTRIM(LEFT(DATENAME(month, getdate()),3)+DATENAME(day,
> getdate())+DATENAME(year, getdate()))
> ...How would I be able to implement the result of the above stament (in th
e
> case, Feb232006) to be the new folder name, i.e., take the result of the S
QL
> select stmt. and pass it to the OS to rename a folder?
> Thanks.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment