Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6067881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:39:22+00:00 2026-05-23T09:39:22+00:00

I have this sql stored procedure which is supposed to look at a particular

  • 0

I have this sql stored procedure which is supposed to look at a particular table and return job numbers based on a date column. This works great except for when its run Saturday morning (and should return all job numbers with a date of Friday, but returns no rows). Any suggestions? Is there some logic problem here I’m not seeing? How might I track this down?

Stored Procedure

ALTER Procedure [dbo].[JC_GetJobsClosedYesterday]

As

SELECT [JobNumber]
  FROM [NCLGS].[dbo].[JobClosedDate]
  Where LastInvoiceDate between dbo.ufn_StartOfDay (DATEADD(d, -1, GETDATE())) AND dbo.ufn_StartOfDay (GETDATE())
  order by JobNumber desc

And the start of day function.

ALTER function [dbo].[ufn_StartOfDay] ( @inDate datetime )

RETURNS DateTime AS 
BEGIN   
DECLARE @Now datetime   
set @Now = @inDate
DECLARE @DayStart datetime
set @DayStart = @Now

set @DayStart = DATEADD (ms, -DATEPART(ms,@Now),@DayStart)
set @DayStart = DATEADD (s, -DATEPART(s,@Now),@DayStart)
set @DayStart = DATEADD (mi, -DATEPART(mi,@Now),@DayStart)
set @DayStart = DATEADD (hh, -DATEPART(hh,@Now),@DayStart)

return @DayStart 
END

EDIT: I’m not having trouble with my date conversion (unless it doesn’t know how to handle Fridays). I need help with the returning no rows part.

SAMPLE DATA:

JobNumber   LastInvoiceDate             DayOfWeek
112117      2011-06-13 00:00:00.000     Monday
112089      2011-06-10 00:00:00.000     Friday
112090      2011-06-10 00:00:00.000     Friday
112068      2011-06-10 00:00:00.000     Friday
112082      2011-06-10 00:00:00.000     Friday

UPDATE: Now I’m really confused. This “no data on fridays” thing has been happening (happened again last friday), but I still can’t figure it out. Is it possible that GETDATE() isn’t returning what I think its returning? Because when I try the following modifications based on @Thomas’s suggestion, both methods get data, but the report that generated based on this code last sat has no data.

DECLARE @date datetime
--SET @date = '2011-06-21 13:42:27.257'
SET @date = '2011-06-11 03:42:27.257'

--Original Code
SELECT [JobNumber]
  FROM [NCLGS].[dbo].[JobClosedDate]
  Where LastInvoiceDate between dbo.ufn_StartOfDay (DATEADD(d, -1, @date)) AND dbo.ufn_StartOfDay (@date)
  order by JobNumber desc

  --Returns 21 records

--Modified based on @Thomas suggestion
Select [JobNumber]
From [NCLGS].[dbo].[JobClosedDate]
Where LastInvoiceDate >= DateAdd( d, DateDiff( d, 0, @date ) - 1, 0 )
    And LastInvoiceDate < DateAdd( d, DateDiff( d, 0, @date ), 0 )
Order By JobNumber Desc

  --Returns 21 records
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:39:22+00:00Added an answer on May 23, 2026 at 9:39 am

    The procedure which updates the jobclosed table runs Monday, Tuesday, Wednesday, Thursday, & Friday mornings. It doesn’t run on Saturdays, so the records aren’t inserted until monday, at which time they won’t be retrieved by my stored procedure. I will schedule the update job to run on Saturday’s also.

    I added the following before the select statement:

    if datepart(dw, GETDATE()) = 7 OR datepart(dw, GETDATE()) = 1
        BEGIN
            Exec dbo.NCL_MaintainJobClosedDateTable
            --Select 'True'
        END
    

    Which will force an update on Saturday and Sunday mornings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL function which is wrapped by a stored procedure: ALTER FUNCTION
I have a stored procedure which is the first step in an SQL Job.
please help me with writing this search sql stored procedure procedure may have different
I have a Stored Procedure which executes some dynamic SQL. I want to use
I have a SQL stored procedure of the form SELECT [fields] FROM [table] WHERE
I have a stored procedure which is building a dynamic sql query and then
I have this code which calls a stored procedure within ZEND. Is there a
I have a stored procedure which returns a Dataset(Table) . How can I use
SQL Server 2005. I have a stored procedure which accepts a few parameters that
I have this sql update statement which updates a remote table. Is there any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.