Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 AD Query Returning 0 rows
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bholmstrom
Yak Posting Veteran

USA
75 Posts

Posted - 03/25/2013 :  16:13:31  Show Profile  Reply with Quote
Good afternoon, I have a procedure that I think is setup correctly, but I'm not seeing any results.

There are no errors when running, here is the proc:

ALTER PROCEDURE [dbo].[ActiveDirectory_GetUserByUserName]
@sAMAccountName varchar(200)

AS
BEGIN

SET NOCOUNT ON;

declare @STRSQL varchar(8000);

select @STRSQL = 'SELECT
sAMAccountName,displayName,givenName,name,title,department
FROM OPENQUERY
(ADSI,''SELECT displayName,givenName,name,title,department
FROM ''''LDAP://DC=RL-DC05,DC=jhc,DC=com'''' where objectClass = ''''User''''
)'

EXEC @STRSQL

END

......................

Any ideas, do I need an ouput of some type?

Thanks

Bryan Holmstrom

bandi
Flowing Fount of Yak Knowledge

India
2242 Posts

Posted - 03/26/2013 :  00:48:34  Show Profile  Reply with Quote
Hi,

first exec the inside code separately... then you will let you know whether result is coming or not.....

declare @STRSQL varchar(8000);

select @STRSQL = 'SELECT
sAMAccountName,displayName,givenName,name,title,department 
FROM OPENQUERY
(ADSI,''SELECT displayName,givenName,name,title,department
FROM ''''LDAP://DC=RL-DC05,DC=jhc,DC=com'''' where objectClass = ''''User'''' 
)'

EXEC @STRSQL


For execution of dynamic query... Syntax sholud be EXEC(@STRSQL)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 03/26/2013 :  14:30:42  Show Profile  Reply with Quote
Why not use PRINT first and then check the output query in a separate query window for syntax errors?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000