Ack! I know this has been posted before, but when I search, I can't find it.
Can someone either answer this question or point me to the thread (if you can recall it) that shows how to use the xp_cmdshell to read a directory and put the results in a temp table?
Essentially I want a list of files from c:\My file path to be inserted in a temp table. I know the code for the xp_cmdshell part of it, but when I try an Insert statement, QA complains.
The code I'm using is (assume @Directory has been declared and set to the proper 'Dir c:\My file path':
I've tried it with Exec and w/o Select and with both Exec & Select. Still won't work. Started re-writing it as a Select Into and ran into the same problem.
Help appreciated! Thanks,
Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
Can someone either answer this question or point me to the thread (if you can recall it) that shows how to use the xp_cmdshell to read a directory and put the results in a temp table?
Essentially I want a list of files from c:\My file path to be inserted in a temp table. I know the code for the xp_cmdshell part of it, but when I try an Insert statement, QA complains.
The code I'm using is (assume @Directory has been declared and set to the proper 'Dir c:\My file path':
Code:
Insert into #Backup(CreateDate, Type, Size, FileName)
(Select xp_CmdShell @Directory)
I've tried it with Exec and w/o Select and with both Exec & Select. Still won't work. Started re-writing it as a Select Into and ran into the same problem.
Help appreciated! Thanks,
Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???