Sp inside sp

This is working in EM:
EXEC Master..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\MSSQLServer\Setup', 'SQLPath'

How can I implement that in a stored procedure:
________________________________________
Declare @InstallPath varchar(100)
SET @InstallPath = Exec Master..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\MSSQLServer\Setup', 'SQLPath'
________________________________________

The above is throwing an error, and beside it return 2 column I only want the 'Data' col that have the path.

Help with syntax or workaround please !
LVL 8
SNilssonAsked:
Who is Participating?
 
imrancsConnect With a Mentor Commented:
create table #ttt (value varchar(100), data varchar(1000))
insert #ttt EXEC Master..xp_regread 'HKEY_LOCAL_MACHINE', 'SOFTWARE\Microsoft\MSSQLServer\Setup', 'SQLPath'
select * From #ttt


Imran
0
 
paeloCommented:
OR

DECLARE @test varchar(20)
EXEC master..xp_regread
     @rootkey='HKEY_LOCAL_MACHINE',
     @key='SOFTWARE\Microsoft\MSSQLServer\Setup',
     @value_name='SQLPath',
     @value=@test OUTPUT
SELECT @test



-Paul.
0
 
imrancsCommented:
to get values in variables

Declare @InstallPath varchar(100)

Select @InstallPath = Data From #ttt


Imran
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
imrancsCommented:
Yes Paul's method is best to get the scaler values.

0
 
SNilssonAuthor Commented:

Your method is working fine Imran, however Paul's returned NULL.
0
 
paeloCommented:
Size problem, sorry.

Change that to DECLARE @test (or @InstallPath) varchar(200) or something larger and it should be fine.


-Paul.
0
 
imrancsCommented:
thanx for the points


Imran
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.