Limit SQL/LDAP Query to 901 Rows

2019-09-04 17:50发布

问题:

I have the following LDAP/SQL Query being used in an ADO.NET SSIS Package and I am trying to figure out how to limit the rows to 901:

 SELECT 
       displayName, 
       cn, 
       extensionAttribute5, 
       streetAddress, 
       telephoneNumber, 
       otherTelephone, 
       info, 
       department, 
       company, 
       givenName, 
       mobile, 
       physicalDeliveryOfficeName, 
       facsimileTelephoneNumber, 
       sn, 
       title, 
       mail
 FROM            
       'LDAP://OU=*****,OU=*****,OU=*****,DC=*****,DC=*****,DC=*****'

 WHERE        
       objectCategory = 'Person' AND 
       objectClass = 'User'

回答1:

Try this :

with x as(
SELECT * FROM OpenQuery ( 
ADSI, 
'SELECT  
  adspath,
  samaccountname    
FROM 
  ''LDAP:// ...''
WHERE 
  objectClass = ''User''
order by samaccountname
') AS tblADSI 
)
select 
      top 901
      adspath,
      samaccountname
 from 
    x