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
Comments