Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

openrowset question Expand / Collapse
Author
Message
Posted Thursday, October 3, 2013 11:46 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 3, 2014 12:33 PM
Points: 474, Visits: 209
I would like to know why I can't run openrowset the way that system stored procedures do? For example, in sys.xp_logininfo, they use it. When I try to copy the part of the code from that SP for use in my code, it gives me the error:

Msg 156, Level 15, State 17, Line 16
Incorrect syntax near the keyword 'OPENROWSET'.

I just don't understand how it can work in the system SP, but I can't run the part of the code I want to use... please help.
Post #1501302
Posted Thursday, October 3, 2013 6:09 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 9:53 PM
Points: 3,438, Visits: 5,390
My suggestion is to show us the code that's giving the error. If possible the simplest case that reproduces the error.


My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1501389
Posted Friday, October 4, 2013 5:45 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Friday, October 3, 2014 12:33 PM
Points: 474, Visits: 209
select 'account name' = domain+N'\'+name,
'type' = convert(varchar(8), case when sidtype = 1 then 'user' else 'group' end),
'privilege' = 'admin',
'mapped login name' = domain+N'\'+name,
'permission path' = 'DOMAIN\GROUPNAME'
from OpenRowset(NetGroupGetMembers, 'DOMAIN\GROUPNAME')

That is the code.
Post #1501543
Posted Friday, October 4, 2013 6:21 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 1:37 AM
Points: 997, Visits: 3,089
kevin.unglesbee (10/3/2013)
I just don't understand how it can work in the system SP, but I can't run the part of the code I want to use... please help.

SQL Server 2005+ doesn't allow system rowset functions to be called directly from user code. So you need to either use the documented system SPs or write your own code using SQLCLR code.




The SQL Guy @ blogspot

@SeanPearceSQL

About Me
Post #1501550
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse