SQL 2012 :: How To Get Name And Timestamp Of File From A Directory
Mar 18, 2015
I want to write a stored procedure or a simple T-SQL snippet that takes a parameter "Directory Path" and gives me the name and datetimestamp associated with each of the files within that directory. I can not use xp_cmdshell since it is not allowed. CLR integration is not enabled on the server either.
Is there any other way at all to achieve this directly from SQL Server using T-SQL?
basically what we need is a query that will allow me to provide a directory and a variable for number of days for instance 1 day old and I want to be able to able to delete all files older than that date and of course I want to be able exclude files of a particular type where I would give it a wild card statement for example say i wanted to save all csv files i would have the wild card say <> '%.csv'
Overall goal: Write a Bulk Insert statement using the UNC path of a filetable directory.
Issue: When using the UNC path of the filetable directory in a Bulk Insert Statement, receiving "Operating system error code 50(The request is not supported.)" Looking for confirmation as to whether this is truly not supported.
Environment: SQL Server 2012 Standard. Windows Server 2008 R2 Standard
I am struggling figuring out the token from a CMDEXEC job (as opposed to TSQL Job). It is not an option to execute the command by enabling the executing CMDs via TSQL, which is why I am using the agent. I have seen the Microsoft Site on tokens but all examples seem to be oriented to TSQL Job Type.
I am trying to delete a particular trace file and at same time keeping the SQL Directory dynamic.Taking it a step further is adding in "deleting if file exist".
We have a hierarchical table of some 2-3k of rows that grows slowly at only 3-5 rows a month, and is never likely to be above 5k, holding file/directory names with an IdParent int value pointing at that items immediate parent or NULL if root
iterative code required to achieve the result I am looking for is best handled in the Application layer, but in this case the design brief is that we must get our results back as a View. Speed of execution and code clarity are secondary 'icing on the cake' issues.
I have tried recursive CTE's and XML FOR solutions but without success, and while I feel the latter is probably the best all rounder the searches I have made and the examples I have read do not seem to solve this particular issue.
Even to find the starting point of the search tree (i.e. the .EXE and the .CSV items) was difficult because the final slash is optional in some of the rows (.e. row 4)
The end result of my view on the above data should return:
Id FilePath 5 C:ProgramFilesExcel.EXE 6 D:DataFilesMyDataList.CSV (note the adding of the missing delimiter between DataFiles and MyDataList)
I have created a File System task which is contained in a Foreach Loop Container. I have .bak files that are populating a directory from a maintenance backup plan.
There is a point where I need to delete the .bak file's after I've zipped them all up.
How do I set the SourceVariable to read through the directory and pick up just the .bak file's in the directory to delete.
I have a question regarding the rowversion / timestamp column. I want to use it to track changes in some tables and I created a non clustered index on the timestamp column (with three includes) to get a better performance while searching / gathering the data. It works very well, but I experienced a big performance hit on the inserts and my first thoughts are that it has something to do with this index.
I know that this NCI has to be updated with every insert and so this could have an impact on performance, but we have a lot of other indexes as well, which are also get updated with every insert. Why this index / column has such a big impact? Our application use a lot of dynamic cursors, maybe it has something to do with that?
I've got a question about the UNIX timestamp solutions, I am using this one:
select convert(datetime, switchoffset(convert(datetimeoffset, dateadd(second, start_date, '19700101')), datename(TzOffset, sysdatetimeoffset()))) from x
This works great for today (wintertime), but when I query the past, say last week, it will still hold the current offset of my server GMT+1, where it was GMT+2.
Is there a way to get always the right date/time from a sql-query?
I have a series of time from 08:10 till 00:55 and a single date in a seperate column. What I need to have is associate the date with each time from 08:10 and when it comes after 23:55 the date needs to be incremented to the next day.
Our database is running in full recovery mode and we backup the logfile every hour and the database file every night. I notice thetimestamp of database file *.mdf remains unchanged a few days. Forexample one database has its timestamp at Apr 15 while it is Apr 20already.I am wondering if this is acceptable. How do I force the system toflush the data and dirty blocks to the disk more frequently? What isthe downside to this?Thanks for any idea.
I have a package that processes a flat file, which is generated by a separate system each weekday around 3:30AM. I would like my package to store the timestamp of the input file and compare it to the timestamp of the next day's file. If they are the same, then the package can exit without reprocessing a particular file again.
So, my first question is whether a package variable can be updated so that its value will persist from one run to the next?
Second, what is the syntax to retrieve the file's timestamp, either directly from the file connection manager or within a script task?
I have 2 years worth of data that are stored in individual .dbf files for each day. Is there a way to 1 quickly import all of these tables into one and 2. move the timestamp from the file name to a date column?
I am pulling files from the FTP site using the FTP task. I want to also capture the date and timestamp of each of these files so that I can insert the values into a database and track when are these files get created normally on the FTP server.
ok...i give up..... can this be done? (sql server 2000) all i want to do is have my stored procedure output some data to a file and i want the filename to include a time stamp. here's my current working file output code: EXEC master..xp_cmdshell 'bcp "select * from CEData..employee" queryout "c:employees.txt" -c -Usa -P' i'd like it to be something like this: EXEC master..xp_cmdshell 'bcp "select * from CEData..employee" queryout "c:employees" + datetime + ".txt" -c -Usa -P' but nothing seems to work.
I am populating oracle source in Sql Server Destination. after few rows it fails it displays this error:
[OLE DB Destination [16]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft OLE DB Provider for SQL Server" Hresult: 0x80004005 Description: "Invalid date format".
I used this script component using the following code in between the adapters, However after 9,500 rows it failed again giving the same above error:
To convert Oracle timestamp to Sql Server timestamp
If Row.CALCULATEDETADATECUST_IsNull = False Then
If IsDate(DateSerial(Row.CALCULATEDETADATECUST.Year, Row.CALCULATEDETADATECUST.Month, Row.CALCULATEDETADATECUST.Day)) Then
dt = Row.CALCULATEDETADATECUST
Row.CALCULATEDETADATECUSTD = dt
End If
End If
I don't know if my code is right . Please inform, how i can achieve this.
First of all apologies for posting this again but I posted it in thewrong place the first time.Can anybody help me with the post below?http://groups.google.com/group/SQL-...5ec9f04d978d0deThanks,Paul
I am creating some applications for Windows Mobile 5.0 devices to be used internally at our company. Each device will run several home grown applications that will all share the same common SQL Mobile database.
What I am wondering is whether or not there is a standard path where such a database is typically stored in Windows Mobile 5.0. I see a folder called Application Data. Is that what it is for, or is that one for something else? I'm not real familiar with the layout of the Pocket PC in general. Could someone tell me where vendors normally put their database file(s)?
I did something stupid. I was messing around with a file DSN and deleted it. I can't seem to recreate it either. I "set the directory" in the ODBC dialogue to a location I liked better and moved the file DSN there. It didn't work when I tried to use the applications on my system later on (huh, shooting self in foot...). (using vista ultimate 64-bit). One of the databases is SQL 2005 Express, and the other is an Access database.
Maybe I lost all my ODBC connections? Neither databases work now... When I am in the File DSN tab and click "Add" I have only two drivers showing up (SQL Native Client and SQL Server) in the Create New Data Source window. Do I need to add an ODBC driver? Any better documentation on File DSNs? (or using the ODBC Administrator)... the help documentation is REALLY lacking!!!
I have a sql compact table that stores a series of directory paths like so: C:F1BackupadministratorCDatakit.zip__--1-07272007124351.F1O C:F1BackupadministratorCDataDeploySMD_FSWsetup.exe__--1-11292007122443.F1O C:F1BackupadministratorCDataDeploySMD_FSWSMD_FSW.application__--1-11292007122443.F1O
Is there a way in sql that I can get just the directory name so the results would look like this: C:F1BackupadministratorCData C:F1BackupadministratorCDataDeploy C:F1BackupadministratorCDataDeploy
Also, is there a way to just get the file names so the results would look like this: kit.zip__--1-07272007124351.F1O setup.exe__--1-11292007122443.F1O SMD_FSW.application__--1-11292007122443.F1O
I've seen some examples with Sql server but they use the reverse function which is not available in sql compact.
Normally (I usually program in JAVA), I would print out the variables to see if there is an issue but I haven't figured out how to do that in SSIS yet.I have to set the Connection string for the Flat File conection using the Expressions tab instead of putting the variable in the connection string tab.Now it works but the file that is spitting out is "testFileDSystem.String[]"
Thanks for reading and helping me out of this problem. I have a directory where I have text file with date as a file name, thus all the files have different file names.
But I want to do is import all the text files into sql server 2000 ,right now i have a DTS package which i have up upload all the text files manually , I do not know how to loap it so that it DTS funcation check all the files in a directory and import it into database.
I will appreciate if anyone can help me out of this .
Hi all, I have scheduled a package to export data from the table to the execl file in the local directory, it work fine. However, when the next time you execute the package it give error on 'file already exists'. Prephap this is due to previously already created a file in the directory.
I try to use drop option in the ssis during creating the package for export, but the result still the same. I do not know the drop option is working, can someone tell me is that working fine? if not what is the solution or possible cause.
There was a 2008 SSRS service running on server "abc".
I have a .Net UI that uses the wsdl at [URL] ....
They deployed SSRS 2012 service on a new server "xyz".
DNS points abc to xyz. Nslookup looks right shows both xyz and abc alias to the same IP.
when I try to go to [URL] .... it redirects to xyz as expected for the host name but the HTTP GET /ReportServer is appended with GET /Reports/ReportServer which doesn't exist and I get an 404 error.
I have no admin rights to see anything and I have no idea if it was an inplace upgrade or a new server. I assume it's new since the actual server name changed in nslookup. Why would it append the default virtual directory when it makes the hop to server "xyz"?
We have a database called Itemphotos. In this table is a field called 'PID' picture ID. We have a photos directory with files like 2181.jpg, 2182.jpg, 2184.jpg. The number is the ID number for the picture of the part. If a record exist in the database based on the PID "Primary Key" , check the directory to make sure the jpg file exist. Here is the code I have so far.
use [ItemPhotos] select pid from dbo.itemdata declare @file_path nvarchar(500) declare @file_exists int set @file_path = 'av-sql2c$inetpubphotosmacolaphotos' + [itemdata].[pid]
i am trying to run an exe using t-sql command and even through job, but it is giving me issues. But if i double click on the exe it runs fine.
For example i created a bat file just to make a directory - mkdir d:example double clicking it, a folder is created BUt through EXEC xp_cmdshell "D:ew.bat" it gives me error - 'D:ew.bat' is not recognized as an internal or external command,
and when i do with the job with command - @command=N'idhimahajanD$ew.bat', it gives an error on execution - Executed as user: NT ServiceSQLAgent$PAXAS. The process could not be created for step 1 of job 0x2FCDDE36F160CD4688D2ACE1D748A99E (reason: Access is denied). The step failed.