Results 1 to 2 of 2

Thread: T-SQL Get Folder Path

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    65

    T-SQL Get Folder Path

    Hi Guys,

    Is there any way using T-SQL to get the 'Program Files' path? E.g Can I get it to resolve something like %PROGRAMFILES% or %WINDIR%?

    I ask cause I want to change the statement below so that its not hard coded to c:\.

    VB Code:
    1. CREATE DATABASE [Static] ON
    2. ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Static.mdf' ),
    3. ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Static_log.ldf' )
    4.  FOR ATTACH ;
    5. GO
    Something like this would be perfect:
    VB Code:
    1. CREATE DATABASE [Static] ON
    2. ( FILENAME = N %PROGRAMFILES% + '\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Static.mdf' ),
    3. ( FILENAME = N %PROGRAMFILES% + '\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Static_log.ldf' )
    4.  FOR ATTACH ;
    5. GO

    Thanks guys,
    Matt.

  2. #2
    Addicted Member
    Join Date
    Oct 2004
    Location
    Clane, Ireland
    Posts
    179

    Re: T-SQL Get Folder Path

    Here is a very nasty way of doing what you want. I'm sure there are better options out there, but it might get you started:

    Code:
    DECLARE @command varchar(255),@iCount integer
    
    --Create Table Log_CmdOutput (Res VarChar(2000))
    
    set @command = 'Set'
    
    DELETE from  Log_CMDOutput
    
    INSERT INTO Log_CMDOutput values(@Command)
    
    INSERT INTO Log_CMDOutput
    EXEC master..xp_cmdshell @Command
    
    Select * From Log_CmdOutPut
    Where Res Like 'ProgramFiles%'
    HTH
    JP

    Please rate the postings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width