SQL - Finding SQL Server Installation Path

If trying to automate creating databases you may need to get the installation path of the SQL Server instance you are connected to, to do this use the following query.
declare @rc int, @dir nvarchar(400) 
  
exec @rc = master.dbo.xp_instance_regread
      N'HKEY_LOCAL_MACHINE',
      N'Software\Microsoft\MSSQLServer\Setup',
      N'SQLPath', 
      @dir output, 'no_output'
select @dir AS InstallationDirectory
Post a Comment

Popular posts from this blog

C# - ListView Item Spacing (Padding)

IIS / ASP.NET - Run all Managed Modules for All Requests (RAMMFAR)

IIS / ASP.NET - Disabling Compatibility Mode/View (Internet Explorer)