Showing posts with label entries. Show all posts
Showing posts with label entries. Show all posts

Wednesday, March 21, 2012

How to detect overlapping Time Entries

Hello,

I am trying to create a SQL Statement which will identify if an entry can be added to a table or not. My table consists of 4 fields which are:

. UserID (Integer)
. StartTime (datetime)
. EndTime (datetime)
. Activity (varchar)

This is a timesheet application. I am trying to identify if a time entered by a user is valid or not. Basically, times cannot overlap. I'm trying to figure out how to code for the following conditions:

Assume an entry already exists for User 1 as follows:

. UserID: 1
. StartTime: 2006-12-30 08:00:00
. EndTime: 2006-12-30 08:15:00
. Activity: Test

I want to make sure that the following entries cannot be added by that user because they would overlap the existing entry:

. StartTime: 2006-12-30 07:50:00
. EndTime: 2006-12-30 08:05:00

OR

. StartTime: 2006-12-30 07:45:00
. EndTime: 2006-12-30 08:45:00

OR

. StartTime: 2006-12-30 08:05:00
. EndTime: 2006-12-30 08:30:00

OR

. StartTime: 2006-12-30 08:05:00
. EndTime: 2006-12-30 08:10:00

Any help is appreciated.

Thanks

Something like this...

select *
from timetrack_tbl
where
userid = 1
AND
(
(
'2006-12-30 07:50:00' between starttime and endtime
OR
'2006-12-30 08:05:00' between starttime and endtime
)
OR
(
'2006-12-30 07:50:00' <= starttime
AND
'2006-12-30 08:05:00' >= endtime
)
)
If you are going to be doing this continually, it might be a good choice for a function with the above code. Create the function to accept the userid, starting and ending dates and return some value indicating whether there is an overlap.

Example:
select dbo.CheckForOverlap(userid, '2006-12-30 07:50:00', '2006-12-30 08:05:00')

return something from the function that tells you if there is an overlap (like a bit, 1 = Overlap, 0 = No Overlap

|||

That worked like a charm.

Thank you so much for the quick response.

-- Val

Wednesday, March 7, 2012

how to delete SQL Server Logs entries under Management

as subject!
i'm using sql server 2000.Mulli
BACKUP LOG databaseane WITH TRUNCATE_ONLY
For moredetails please refer to the BOL.
"Mullin Yu" <mullin_yu@.ctil.com> wrote in message
news:u#ZeB0yBEHA.3748@.TK2MSFTNGP11.phx.gbl...
> as subject!
> i'm using sql server 2000.
>|||hi mullin,
You cannot delete the "sql server logs" from Enterprise manager.These files
are stored under
folder
C:\Program Files\Microsoft SQL Server\log\
-- OR (for named instance)
C:\Program Files\Microsoft SQL Server\MSSQL$<instance_name>\log\
delete them from this location, and right click in the enterprise manager on
"sql server logs"
and click on refresh.
it wont show the logs that have been deleted.
Note: you can not delete current errorlog file.
Also one more point to be noted that, if your current errolog has grown big,
you can recyle it
forcefully by running sp_cycle_errorlog from query analyzer
Vishal Parkar
vgparkar@.yahoo.co.in

How to delete repeated entries from table using T-SQL statement

Hi Friends..

I want delete repeated entries which comes twice in a table. How to delete that extra entry and keep each single entry using T-SQL statement(SQL server 2000). Please give me the example.

Thanks & Regards,
Ravi.Hi,

You may select distinct the duplicate entry and save it in a temporary table, then delete the double entry to the main table and insert the content of the temporary table to the main table.|||Hi,

Thank you for giving solution, but still I don't know how to do that, can you send me code and e.g. It will help me for understanding. I hope you will give this solution very soon.

Thanks & Regards,
Ravi.