| Author |
Topic |
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2004-09-24 : 13:05:06
|
| I am trying to get a lastFile date modified using the following sp.However when I am trying to pass a parameters from cursor it is not working. Please helpCREATE PROCEDURE [dbo].[MyTEST] ASDECLARE @ImportDirectory varchar(50)DECLARE @ImportFileName varchar(50)DECLARE File_Info CURSOR FOR SELECT ImportDirectory,ImportFileName FROM FileLocation OPEN File_InfoFETCH NEXT FROM File_Info INTO @ImportDirectory,@ImportFileNameWHILE @@FETCH_STATUS = 0BEGIN insert into dirlist(filename) exec master..xp_cmdshell 'dir ' + @ImportDirectory + @ImportFileName VALUES (@ImportDirectory,@ImportFileName)FETCH NEXT FROM File_Info INTO @ImportDirectory,@ImportFileNameENDCLOSE File_InfoDEALLOCATE File_Info |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-09-24 : 13:14:11
|
| What is the error? Your stored procedure doesn't have any input parameters but you say you are passing parameters. How does that work?Tara |
 |
|
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2004-09-24 : 13:38:02
|
| I am using cursor:SELECT ImportDirectory,ImportFileName FROM FileLocationerror:Server: Msg 170, Level 15, State 1, Procedure MyTEST, Line 14Line 14: Incorrect syntax near '+'. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-09-24 : 13:43:25
|
| Ah, I see your problem. You can't build the string at the same time calling xp_cmdshell. So you have to build up the string to execute in a variable, then just execute the variable. Like this:DECLARE @command NVARCHAR(256)SET @command = 'dir' + @ImportDirectory + @ImportFileNameexec master..xp_cmdshell @commandFor why, see the comments in this blog entry that I made:http://weblogs.sqlteam.com/tarad/archive/2004/03/29/1129.aspxTara |
 |
|
|
sardinka
Posting Yak Master
142 Posts |
Posted - 2004-09-24 : 14:52:14
|
| Below is my compete code. When I try to run it running forever...why?DECLARE @command NVARCHAR(256)DECLARE @ImportDirectory varchar(50)DECLARE @ImportFileName varchar(50)DECLARE File_Info CURSOR FOR SELECT ImportDirectory,ImportFileName FROM FileLocation OPEN File_InfoFETCH NEXT FROM File_Info INTO @ImportDirectory,@ImportFileNameWHILE @@FETCH_STATUS = 0SET @command = 'dir' + @ImportDirectory + @ImportFileNameBEGIN insert into dirlist(filename) exec master..xp_cmdshell @commandFETCH NEXT FROM File_Info INTO @ImportDirectory,@ImportFileNameENDCLOSE File_InfoDEALLOCATE File_Info |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-09-24 : 15:07:12
|
| Because it's malformed....you need to move the SET before the BGIN, and then replicate the statement after the fetch in the loop...Brett8-) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-09-24 : 15:12:04
|
| Why is this even being done in T-SQL? This seems like a job for VBScript. Is this an Admin script?Tara |
 |
|
|
kselvia
Aged Yak Warrior
526 Posts |
Posted - 2004-09-24 : 17:35:10
|
| Another way to get file info without parsing output from dir:Create table ##filedetails(alternatename char(20),size char(20),creation_date char(20),creation_time char(20),last_written_date char(20),last_written_time char(20),last_accessed_date char(20),last_accessed_time char(20),attributes char(20))INSERT ##filedetails EXEC master.dbo.xp_getfiledetails "\\server\share\path\file.name"select * from ##filedetails --KenI want to die in my sleep like my grandfather, not screaming in terror like his passengers. |
 |
|
|
clarkbaker1964
Constraint Violating Yak Guru
428 Posts |
Posted - 2004-09-24 : 18:54:08
|
| Don't see xp_getfiledetails in BOL or in the QA object listSurf On Dude! |
 |
|
|
kselvia
Aged Yak Warrior
526 Posts |
Posted - 2004-09-24 : 19:00:21
|
| I guess it's undocumented. sp_helpextendedproc will show it. It still works in SQL 2005.--KenI want to die in my sleep like my grandfather, not screaming in terror like his passengers. |
 |
|
|
|