home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / DistQuery / dq.sql
Encoding:
Text File  |  1999-02-15  |  1.8 KB  |  56 lines

  1. '-- This tells SQL Server to associate word 'ADSI' with ADSI OLE DB provider - 'ADSDSOObject'
  2. sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'adsdatasource'
  3. go
  4.  
  5. '-- Get the information for Active Directory
  6. SELECT * FROM OpenQuery( ADSI,'<LDAP://DC=srinivacdom,DC=nttest,DC=Microsoft,DC=com>;(objectClass=user);adspath;subtree')
  7.  
  8. '-- Or you can also use SQL Dialect
  9. SELECT * FROM OpenQuery( ADSI, 'SELECT name, adsPath FROM ''LDAP://DC=Microsoft,DC=com'' WHERE objectCategory = ''Person'' AND objectClass= ''user''')
  10.  
  11. '--Creating a view
  12. CREATE VIEW viewADUsers AS
  13. SELECT * FROM OpenQuery( ADSI,'<LDAP://DC=Microsoft,DC=com>;(&(objectCategory=Person)(objectClass=user));name, adspath;subtree')
  14.  
  15. SELECT * from viewADUsers
  16.  
  17. '-- Creating a SQL table, a employee performance review table
  18.  
  19. CREATE TABLE EMP_REVIEW
  20. (
  21. userName varChar(40),
  22. reviewDate datetime,
  23. rating decimal 
  24. )
  25.  
  26. '--Insert few records
  27.  
  28. INSERT EMP_REVIEW VALUES('Administrator', '2/15/1998', 4.5 )
  29. INSERT EMP_REVIEW VALUES('Administrator', '7/15/1998', 4.0 )
  30.  
  31.  
  32.  
  33. '--Now join the two!
  34.  
  35. SELECT ADsPath, userName, ReviewDate, Rating 
  36. FROM EMP_REVIEW, viewADUsers
  37. WHERE userName = Name
  38.  
  39. '--- Creating a report for this join
  40. CREATE VIEW reviewReport
  41. SELECT ADsPath, userName, ReviewDate, Rating 
  42. FROM EMP_REVIEW, viewADUsers
  43. WHERE userName = Name
  44.  
  45.  
  46. '-----------------------------------------------------
  47. '--- Advanced Operations
  48. '------------------------------------------------------
  49. --Maps the user name to the OLE DB user name (in this case Active Directory)
  50. sp_addlinkedsrvlogin ADSI, false, 'MICROSOFT\Administrator', 'CN=Administrator,CN=Users,DC=Microsoft,DC=com', 'passwordHere'
  51. go
  52.  
  53. '-- To stop supplying credential
  54. sp_droplinkedsrvlogin ADSI,'MICROSOFT\Administrator'
  55. ator'
  56.