Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

GetDate in Job/Stroed Procedure

$
0
0

Hi everyone,

I am going to create a job that will kick off a stored procedure that will get all of the new employees in AD from the past week. My job will run every Monday at 12:00am. I have successfully queried AD, and I created a view, just in case I want ot join the AD data to another table later on down the road. I have created the stored procedure to run my SSRS report. I am undecided on how to get the new employees in the past week. I have tried this:

ALTER PROCEDURE [dbo].[P_NEW_AD_EMPLOYEES_LIST_SEL]

	--@StartDate Datetime //pass in GetDate from job???
AS
BEGIN
	
	SET NOCOUNT ON;

    SELECT     name, mail, createTimeStamp, physicaldeliveryofficename
FROM         OPENQUERY(ADSI, 
                      'SELECT physicaldeliveryofficename,
    createTimeStamp,mail,name  
   FROM  ''LDAP://myServer/myDomain=com''   
   WHERE objectCategory = ''Person'' AND objectClass= ''User'' 
  ')
                       AS tblADSI
WHERE     (GETDATE()<= 7 and name IS NOT NULL)  
END
GO
createTimeStamp is the date the employee was created in AD. I want all employees from seven days before this stored proc runs. Can I pass the GetDate to my proc from the job? or just put it in the stored proc and leave the @startDate out? I would really like some direction on the logic.


mark a fisher


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>