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 = 'SELECTsAMAccountName,displayName,givenName,name,title,department FROM OPENQUERY(ADSI,''SELECT displayName,givenName,name,title,departmentFROM ''''LDAP://DC=RL-DC05,DC=jhc,DC=com'''' where objectClass = ''''User'''' )'EXEC @STRSQL
For execution of dynamic query... Syntax sholud be EXEC(@STRSQL)