Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Get file name from Script

Author  Topic 

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2013-10-24 : 09:35:28
Is there anyway that if you are applying a Database Script saved in a file, that we can through SQL, grab the name of this file?

We are planning to make a Stored Procedure that will log every time a Database Script is applied to a Database. Instead of writing: LogStep('xxx05.sql'), it would be easier for us to just write LogStep, provided somehow the file name can be determined.

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-24 : 11:07:11
How are you running the script? If you are using SQLCMD with the -i option, then one way would be to have another statement that inserts the same filename into your log table.

In general, I don't think there is any T-SQL feature that allows you to capture the name of a file from which the script comes.
Go to Top of Page

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2013-10-24 : 13:24:22
Thanks, I'm running it through the SSMS.
Go to Top of Page
   

- Advertisement -