Need Help Getting The Day Shift After Midnight

Dec 2, 2006

Hello there,
I am having a small problem which been challenging me for few days and
need help or advice.

I am trying to calculate the day-shift for employees based on the time
they started and finish working, I will only have 2 shifts 1 or 2 .
Shift one changes based on the location however any thing else is shift
2. The problem I am having is when someone signed in after midnight; I
need to report his time under shift 2 for the previous day date. So if
he signs at 12:30 AM on 12-12-2006, I need to report that as shift 2 on
12-11-2006 and that’s where my problem is. Is there a way to subtract
the date by 1. I am using SQL Server and here is a simplified tables I
am working with:


Employee table
EmployeID LocationID StartTime EndTime
123 555 11:00:00 AM 3:00:00 PM
183 559 7:00:00 AM 11:00:00 AM




Shift table
ShiftNumber LocationID StartTime EndTime
1 555 7:00:00AM 2:00:00PM
2 555 2:00:00PM 12:00:00AM
1 559 6:00:00AM 4:00:00PM
…..


So I am trying something like

CASE WHEN (select ShiftNumber FROM Shift WHERE LocationID=TR.LocationID
AND
(TR.StartTime>=StartTime
AND
TR.EndTime<= EndTime)
) =1 THEN 1
ELSE
WHEN (select ShiftNumber FROM Shift WHERE LocationID=TR.LocationID
AND
(TR.StartTime>=StartTime
AND
TR.EndTime<= EndTime)
) =2 THEN 2
ELSE
?????????????? NEED HELP HERE WHEN EMPLOYEE SIGN AFTER MIDNIGHT
END
)
FROM

Employee TR

INNER JOIN Shift ON LocationID = TR.LocationID








*** Sent via Developersdex http://www.developersdex.com ***

View 3 Replies


ADVERTISEMENT

What Happens At Midnight ?

Oct 17, 2006

Everyday at just gone midnight, my MSSQL server won't accept connections. About 25 minutes later, it seems to be OK. There's no third party backup software running on this machine which is MSSQL server aware. Has anyone any suggestions as to why this might be happening ?

The client app trying to use the db reports

17/10/2006 00:02:04 Email2DBServer Cannot open database "Email2DB" requested by the login. The login failed. From OpenLocalDatabase

and there's an entry in the event log

Event Type: Failure Audit
Event Source: MSSQL$EMAIL2DB
Event Category: (4)
Event ID: 18456
Date: 17/10/2006
Time: 00:02:04
User: NAVIGATOR-BATHavigator-service
Computer: NAVIGAT2A
Description:
Login failed for user 'NAVIGATOR-BATHavigator-service'. [CLIENT: <local machine>]
Data:
0000: 18 48 00 00 0e 00 00 00 .H......
0008: 13 00 00 00 4e 00 41 00 ....N.A.
0010: 56 00 49 00 47 00 41 00 V.I.G.A.
0018: 54 00 32 00 41 00 5c 00 T.2.A..
0020: 45 00 4d 00 41 00 49 00 E.M.A.I.
0028: 4c 00 32 00 44 00 42 00 L.2.D.B.
0030: 00 00 07 00 00 00 6d 00 ......m.
0038: 61 00 73 00 74 00 65 00 a.s.t.e.
0040: 72 00 00 00 r...

View 11 Replies View Related

Clear DB Fields At Midnight

Apr 14, 2004

I have a dataBase named pricesDB. I would like to clear all the prices column everyday at midnight.
How should i do that???

View 1 Replies View Related

Manipulating GetDate() To Start At Midnight Rather Than Now

Apr 29, 2008

Hi Folks,

I am trying to find the best way to use the getDate() function in SQL Server CE to return a date and time which starts at midnight rather than the value of now which getDate() returns.

When running getDate I get the value of 29/04/2008 10:48:33 returned, but I want to return 29/04/2008 00:00:00 instead.
The only way I can see to do this is like so:




Code Snippet

--SQL to get shifts for next 7 days.
select * from SHIFTS

where STARTDATE between
--Today at midnight 2008-04-29 00:00:00.000

(convert(datetime,

convert(nvarchar,(datepart(yyyy,getdate()))) + '/'

+

convert(nvarchar,(datepart(MM,getdate()))) + '/'

+

convert(nvarchar,(datepart(dd,getdate())))

))

and
--7 days from now at night 2008-05-05 00:00:00.000
(

convert( datetime,

convert(nvarchar,(datepart(yyyy,getdate()+6))) + '/'

+

convert(nvarchar,(datepart(MM,getdate()+6))) + '/'

+

convert(nvarchar,(datepart(dd,getdate()+6)))

))





Is there a better way to do this rather than this long winded method?

Thanks,

Morris

View 1 Replies View Related

Roll Date If Time Entered Is After Midnight

Feb 19, 2008

Hi again,
 In ASP.net, is there any elegant way to handle a set of time inserts from a form when the 2nd time is past midnight?
Specifically, I have a form with 2 textboxes on it (startTime and endTime) that are set up to accept time values (using AJAX MaskedEditExtender for formatting/validation - pretty cool). This data is posted to a sub that enters the data into a table (T_Details). However, I've noticed that the data inserted as part of the record (SQL field is smalldatetime) doesn't take into account the fact that a time value past 23:59:59 in the "endTime" textbox is a time on the next day - it simply rolls to an A.M. date for the same day as the date for the pre-midnight value from the "startTime" textbox. 
I'm sure that I can simply do some conditional coding and modify the date if necessary but is there a better way to do it? Thanks as always...this forum is a great resource

View 8 Replies View Related

SQL 2012 :: Getdate Pulls Time From Midnight To 23:59 Hours?

Jun 23, 2015

What is the proper way to ensure when pulling date between two getdates, that you include from midnight of the first getdate to 23:59 hours in the second getdate?

WD.WRKD_WORK_DATE
and WD.WRKD_WORK_DATE between DATEADD(DD, - 11, GETDATE())
and DATEADD(DD, - 5, GETDATE())

View 3 Replies View Related

Items Centered Or Right Of Center Shift Far Right

Dec 27, 2007

Hello,

I have a BIDS project with 14 reports, all formatted the same way. On one report, any text box or image that is placed in the center or right of center in the form, shifts very far to the right of the tables and charts when it's rendered.



The text box placed at the top left of the form stays put. This is really wierd.

Has anyone ever heard of anything like this.

I have a couple of screen shots if you have a place I can put them.

Thanks

Dan

View 3 Replies View Related

Deciphering Employee Shift Data

Feb 11, 2008

Here is my current challenge that I realize I could do a few different ways but nothing efficient or flexible comes to mind. Hoping one of you guys can help me out with an elequent efficient T-SQL script.

Employee workstate information in our system is stored by segment. Segment 1 cooresponds to the entire shift while segments greater than 1 coorespond to subsequent breaks during the shift (Segment 1). i.e.

SegmentNumber SegmentStart SegmentEnd

1 10:00am 06:00pm
2 12:00pm 13:00pm
3 03:15pm 04:00pm


What I would like to do is generate continuous nonoverlapping records. i.e.

SegmentNumber SegmentStart SegmentEnd

1 10:00am 12:00pm
2 12:00pm 13:00pm
3 13:00pm 03:15pm
4 03:15pm 04:00pm
5 04:00pm 06:00pm


*Notice End has changed to match start of first break and so on. Also records have been added to fill gaps between breaks during the shift.

What adds to the challenge is that the segment number for a given employee/report day can be 1 (meaning no breaks) to any number (lots of breaks). The segment start and end times can be any increment. In addition Breaks can be divided into paid time and unpaid time but I imagine given a solution to the above I could apply it to another level down on my own.

Thank you in advance for your help!

View 3 Replies View Related

SHIFT + SPACE In Table Editor

Feb 6, 2007

The default behaviour for pressing SHIFT + SPACE when editing text inside a cell in the Table Editor view in Microsoft SQL Server Management Studio Express is to change focus to select all cells comprising the current row. This behaviour lends itself to the default behaviour for pressing SHIFT + {LEFT | RIGHT | UP | DOWN } in changing the focus to select adjacent cells.

However, I find this is quite annoying as the SHIFT + SPACE combination is quite a common miss-type when entering text in UpperCaps or when entering text with spaces while holding the SHIFT key.

Anyone else have this gripe with MSSMSE? Anyone know how to disable this behaviour?

Simon

View 2 Replies View Related

Making The Shift From Access SQL To 'Real' SQL ;-)

Apr 10, 2006

for the record, this is my first post and i'm not sure this is the right place to post, but it makes sence to me.

i've been spending a great deal of time with our new MS SQL server and love it but i've noticed there's a fairly large diff between the SQL i'm used to seeing in MS Access and the SQL that the server uses. as you can see by my below statement i'm starting to get the hang of this but i still run into new issues...

my question... what's wrong with my IIf statements? this is what the server spits out...

Msg 156, Level 15, State 1, Line 4

Incorrect syntax near the keyword 'LIKE'.

[ACCPAC_OESHDT].[TERRITORY] is an nvarchar(6) and contains data such as '1', '2', '3', etc...

i've tried many many variants and always have the same outcom. i've tried casting as an int, rtrim to rid the value of any possible white space, expanded versions.

oh, almost forgot... my environment is... I open the SQL Management Studio then logon to SQL Database Engine and then create a New Query.  

i'm stuck, please advise. ;-)

SELECT

ACCPAC_OESHDT.YR,

ACCPAC_OESHDT.PERIOD,

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[1-4]','Group A',

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[5-7]','Group B',

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[89]','Group C','_Unknown Territory'))) AS TERRITORY,

SUM(CAST([SAMTSALES] AS MONEY)) AS Sales

FROM ACCPAC_OESHDT

GROUP BY

ACCPAC_OESHDT.YR,

ACCPAC_OESHDT.PERIOD,

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[1-4]','Group A',

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[5-7]','Group B',

IIf([ACCPAC_OESHDT].[TERRITORY] LIKE '[89]','Group C','_Unknown Territory')))

HAVING ((SUM(CAST([SAMTSALES] AS MONEY)))>0);

View 7 Replies View Related

Transact SQL :: Identify Shift Which Is Falling To Next Day

May 17, 2015

I have the following shift table:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

[code]...

I need to identify which shift is currently running on by providing the current time.I used the following query to get the result. It is giving correct result for Morning & Afternoon Shift but failed to produce result for Night Shift.

SELECT ShiftName, Shiftid
FROM WHShifts
WHERE DATEPART(HOUR, @Currenttime)>=(DATEPART(HOUR,CAST(ShiftInTime AS Datetime))) AND DATEPART(HOUR, @Currenttime)<=(DATEPART(HOUR,CAST(ShiftOutTime AS Datetime)))

Is there any way to find out the night shift from a given time.

View 15 Replies View Related

Transact SQL :: Calculating Date And Time For 3rd Shift

Jul 13, 2015

We are maintaining 3 Shifts in our database. Problem in maintaining date and time for 3rd Shift. For example, today date is 13th July and third shift timing is 11 PM - 7 AM. Then I have to display the beginning date as 13/07/2015 11 PM and end date as 14/07/2015 7 AM. Please find the data(in seconds) available in database which I need to use for my calculation.

Date(Fcreacion)
Start time in Seconds(Hcreacion)
End time in seconds(Hcerrar)
turno(Shift)

[code]...

View 3 Replies View Related

Transact SQL :: Shift Analysis - CAST Using Times

Nov 9, 2015

I am doing some analysis on shifts and what I want to do is say if the time from a timestamp field is between 00:00 and 05:59 then the figures belong to the day before.  Eg.  We have a night shift that work 22:00 - 06:00.

Here is my coding which logically looks sound to me but when I run it, it has an error:

SELECTe.ID,
CAST(e.TimestampasDate)asEventDate,
CAST(e.TimestampasTime)asEventTime,
CASE
WHENCAST(e.TimestampasTime)BETWEEN'00:00:01'and'05:59:59'
THENCAST(e.TimestampasDate)-1
ELSECAST(e.TimestampasDate)
END
FROMIntouch.Event

View 5 Replies View Related

Grouping By Custom Datepart For Shift Patterns

Apr 27, 2006

My application has a log table with a timestamp field which represents the time when the record was inserted.

We would like query the the table and group the results into date units based on the value of the timestamp.

The grouping specification is held in another table but only specified for a single week.

For example

WeekDay Start End

1 06:00:00 14:00:00

2 08:10:00 17:00:00

What this specification means is that when the log table is queried records with a timestamp that fall on a Monday between 06:00:00 and 14:00:00 should be grouped together, on Tuesday the group is records between 08:10:00 and 17:00:00 and so on...

The only way I can think of doing this is to generate a temporary table when the log table is queried that has a unique record for each time period for the span of the query and then attempt to join this table to the log table using the timestamp and then group based on the temporary table unique ID.

I'm not sure how to generate such a temporary table from the specification table so any help would be appreciated.



Thanks in advance.

View 5 Replies View Related

How To Display Unicode Data Stored In MSSQL As Shift-jis In ASP

Nov 22, 2006

 We are experiencing problems in presenting Unicode data stored in MSSQL as Shift-jis format in ASP application.
In MSSQL we are storing kanji text in database with a field type as nchar. Other application loads these tables using codepage 932. In MSSQL data is stored in Kanji correctly.
In ASP application, when we are trying to read data from these tables, Kanji characters are coming as '?????'. We are using shift-jis character set in ASP.
Templates for field and column header uses shift-jis, but a record set coming from MSSql is Unicode.
Is there a  way to convert from Unicode to Shift-jis in MSSql or in ASP .
Please help!!

View 1 Replies View Related

Retrieving A Datetime With A Time Of Midnight (from A Typical Datetime)

Sep 7, 2007

Nothing difficult, I just need a way to generate a new datetime column based on the column [PostedDate], datetime. So basically I want to truncate the time. Thanks a lot.

View 5 Replies View Related

Report Objects Shift To Right On Very Wide Report - Why?

Mar 13, 2007

Greetings,

I have a very wide report of more than 20 inches. I've placed several parameter values in the report header section so that the user can see what filters have been applied to the data. The testboxes shift their position several inches to the right when the report is run from the Report Manager.

Is there a way to make sure that a textbox is displayed at an absolute position? I thought maybe there would be a property on the report or body object that controls this but I don't see one.

Thanks for your help,

BCB

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved