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

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 AD Query Returning 0 rows

Author  Topic 

bholmstrom
Yak Posting Veteran

76 Posts

Posted - 2013-03-25 : 16:13:31
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-03-26 : 00:48:34
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

52326 Posts

Posted - 2013-03-26 : 14:30:42
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
   

- Advertisement -