Active Directoryに接続し、特定のグループのユーザーをプルするための次のコードがあります。以下のコードは正常に機能しますが、調べたい部門をハードコーディングする必要があります。
パラメータをopenqueriesの2番目のパラメータ(2番目のコード)に渡そうとしていますが、エラーが発生し続けます。引用符に問題があることはわかっています。助けていただければ幸いです。
select *
from openquery(ADSI, '
select
givenName,
sn,
sAMAccountName,
displayName,
mail,
telephoneNumber,
mobile,
physicalDeliveryOfficeName,
department,
division
from ''LDAP://DC=directorysync,DC=cfc, DC=com''
where objectCategory = ''Person''
and objectClass = ''user''
and department = ''Production''
AND displayname <> ''0_UW_Template_Remote''
ORDER BY displayName
')
select *
from openquery(ADSI, '
select
givenName,
sn,
sAMAccountName,
displayName,
mail,
telephoneNumber,
mobile,
physicalDeliveryOfficeName,
department,
division
from ''LDAP://DC=directorysync,DC=cfc, DC=com''
where objectCategory = ''Person''
and objectClass = ''user''
and department = '''+@Department+'''
AND displayname <> ''0_UW_Template_Remote''
ORDER BY displayName
')