Showing posts with label adatetime. Show all posts
Showing posts with label adatetime. Show all posts

Friday, March 23, 2012

Read file info via Transact SQL....

Hi there.
Any ideas how I could go about getting a file's "Created" date/time into a
datetime variable using T-SQL? I'm thinking along the lines of using the
results of a call to xp_cmdshell but as to what command I should call...
well...
Any help would be appreciated!Sure you can use any DOS command via xp_cmdshell. Here is a rough example
of reading datetimes.
CREATE TABLE #dirlist (FName VARCHAR(1000))
-- Insert the results of the dir cmd into a table so we can scan it
INSERT INTO #dirlist (FName)
exec master..xp_cmdshell 'dir /OD C:\Backups\*.trn'
-- Remove the garbage
DELETE #dirlist WHERE
SUBSTRING(FName,1,2) < '00' OR
SUBSTRING(FName,1,2) > '99' OR
FName IS NULL
SELECT SUBSTRING(FName,40,40) AS FName
FROM #dirlist
WHERE CAST(SUBSTRING(FName,1,20) AS DATETIME) < @.DelDate
AND SUBSTRING(FName,40,40) LIKE '%.TRN'
Andrew J. Kelly SQL MVP
"len" <len@.discussions.microsoft.com> wrote in message
news:74125E9D-6E97-46FE-855C-CA2913135FE3@.microsoft.com...
> Hi there.
> Any ideas how I could go about getting a file's "Created" date/time into a
> datetime variable using T-SQL? I'm thinking along the lines of using the
> results of a call to xp_cmdshell but as to what command I should call...
> well...
> Any help would be appreciated!|||Rather than placing this functionality in a stored procedure, consider a DTS
package and VBScript task.
http://msdn.microsoft.com/library/d...
flow_0793.asp
http://www.sqldts.com/?246
http://msdn.microsoft.com/library/d...efc4b9f49c7.asp
"len" <len@.discussions.microsoft.com> wrote in message
news:74125E9D-6E97-46FE-855C-CA2913135FE3@.microsoft.com...
> Hi there.
> Any ideas how I could go about getting a file's "Created" date/time into a
> datetime variable using T-SQL? I'm thinking along the lines of using the
> results of a call to xp_cmdshell but as to what command I should call...
> well...
> Any help would be appreciated!sql