SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


DATEADD


DATEADD

Author
Message
TSQL Tryer
TSQL Tryer
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1769 Visits: 715
Good Morning.

I have the following script that pulls me back a number of "jobs".

SELECT   DISTINCT       JOB.[PLACE-REF] AS 'UPRN'
,TEN.[tenancy-ref] AS 'Tenant_Number'
,JOB.[JOB-NO] AS 'PK_Job_Number'
,STAGE1.[STAGE.Completion_Date] AS 'Completion_Date'
,TEN.[corr-name1] AS 'Tenant_Name'





FROM [dbo].[IH_RM-JOB] AS JOB

INNER JOIN
(

SELECT STAGE.[job-no] AS 'STAGE.Job_Number'
,STAGE.[stage-date] + STAGE.[stage-time] AS 'STAGE.Completion_Date'


FROM [dbo].[IH_RM-STAGE-HISTORY] AS STAGE

WHERE STAGE.[stage-code] = '93'

) AS STAGE1
ON JOB.[JOB-NO] = STAGE1.[STAGE.Job_Number]


INNER JOIN
[dbo].[IH_IH-LOCATION] AS LOC
ON LOC.[place-ref] = JOB.[PLACE-REF]
INNER JOIN [dbo].[IH_RE-TNCY-PLACE] AS TPLAC
ON TPLAC.[place-ref] = LOC.[place-ref]
INNER JOIN [dbo].[IH_RE-TENANCY] AS TEN
ON TPLAC.[tncy-sys-ref] = TEN.[tncy-sys-ref]








WHERE LOC.[scheme] <> 'LEASED'
AND TEN.[tncy-status] <> 'FOR'




ORDER BY STAGE1.[STAGE.Completion_Date]



What I want to do is schedule this script to run every week. But when it runs it only pulls through the jobs of the last 7 days.

Is it the Where clause that I would place this ? Could you please advise how I could just pull back a weeks worth of jobs from the last 7 days?
Using the STAGE1.[STAGE.Completion_Date]

Thanks
Phil Parkin
Phil Parkin
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50945 Visits: 21153
Yes - add it to the WHERE bit:

WHERE [existing conditions]
AND STAGE1.[STAGE.Completion_Date] > dateadd(d,-7,getdate())


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
TSQL Tryer
TSQL Tryer
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1769 Visits: 715
Legend. Thanks Phil
Phil Parkin
Phil Parkin
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50945 Visits: 21153
Ryan Keast (5/28/2014)
Legend. Thanks Phil


No problem. And if you want to ignore the time component, you might like to use

dateadd(d,-7,cast(getdate() as date))

instead.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search