Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Here is my stored procedure:

CREATE PROCEDURE dbo.IndividualByMonth

@start datetime,
@finish datetime,
@staff nvarchar

AS

DECLARE @EIDs as int

SELECT @EIDs = EmployeeId
FROM StaffList
WHERE Username = @staff


SELECT TOP 100 PERCENT dbo.Timesheets.Id, dbo.Timesheets.Employee, dbo.Timesheets.[Date], 
		dbo.Timesheets.Parent, dbo.Timesheets.Child,  dbo.Timesheets.Hours, dbo.Timesheets.Comments, 
			SUM(dbo.Timesheets.[Hour]) AS [hour], SUM(dbo.Timesheets.[Minute]) AS [minute]
FROM dbo.Timesheets INNER JOIN
                      dbo.StaffList ON dbo.Timesheets.Employee = dbo.StaffList.EmployeeId
WHERE (dbo.Timesheets.Employee = @EIDs) AND (dbo.Timesheets.[Date] BETWEEN CONVERT(DATETIME, @start,103) AND CONVERT(DATETIME, 
                     @finish,103))
GROUP BY dbo.StaffList.Surname, dbo.StaffList.Forename, dbo.Timesheets.Id, dbo.Timesheets.Parent, dbo.Timesheets.Child, dbo.Timesheets.Hours, 
                      dbo.Timesheets.Comments, dbo.Timesheets.OffSite, dbo.Timesheets.Employee, dbo.Timesheets.[Date]
ORDER BY dbo.StaffList.Surname, dbo.StaffList.Forename

GO

 

If I take the 2nd select statement, and fill in 1 for the variable @EIDs and '01/11/2007' for @start and '01/12/2007' for @finish and place it in a view I get back the rows that I am looking for.

 

However, if I simply pass in the above two dates I cannot get back any data.

 

Any suggestions?

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

  • *Experts*
Posted

What DataType is column TimeSheets.Date? Silly question, I know... but you're comparing the column to a varchar in your query so I thought I'd ask.

 

If it's a datetime and your variables are both datetime, then I'd think it would work just fine. Keep in mind that datetime DOES have a time portion so if your table values have time stored, then your "BETWEEN" will likely not include records on the @enddate date.

 

For example:

Row 0: Date = '01/11/2007 1:32pm'

Row 1: Date = '01/12/2007 2:32pm'

 

If @start = '1/11/2007' and @end = '1/12/2007' then it will NOT pick up Row 1.

 

The two common fixes are:

1. Change the query to not use BETWEEN, but use something like:

TimeSheets.Date >= @start and TimeSheets.Date < (@enddate + 1 day)

 

You'll use something like DATEADD(d, 1, @enddate) for that last bit.

 

2. Change the @enddate to be the END of the date you're checking:

SET @endDate = '1/12/2007 11:59:59pm'

TimeSheets.Date BETWEEN @start and @endDate

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...