Transact SQL :: How To Query Records For A Date Range
Oct 14, 2015
This one is making my head hurt! Trying to figure out how to query for records between date range. The records have a start_date and an end_date field. The end_date field maybe null.
For example, say you wanted to see the records of everyone checked into a hotel during a given date range. You need to account for the people that checked in before you @start_date parameter and may check out after your @end_date parameter.
fyi- As for the null end_date field, think of this as they have checked in and not sure when they will checkout yet.
View 7 Replies
ADVERTISEMENT
Nov 18, 2015
I tried to ask a similar question yesterday and got shot down, so I'll try again in a different way. I have been looking online at the gaps and islands approach, and it seems to always be referencing a singular field, so i can't find anything which is clear to get my head around it.In the context of a hotel (people checking in and out) I would like to identify how long someone has been staying at the hotel (The Island?) regardless if they checked out and back in the following day.
Data example:
DECLARE @LengthOfStay TABLE
(
PersonVARCHAR(8) NOT NULL,
CheckInDATE NOT NULL,
CheckOutDATE NULL
[code]...
View 7 Replies
View Related
Dec 2, 2015
I have a table of errors with a DateTime field for when the error occurred. I want to query the table for a given date range omitting the time portion. What is the most efficient way to perform this query?
View 5 Replies
View Related
May 21, 2015
I have a data structure like this
UID , Name, amount, start date End Date
1 A 10 2015-05-01 00:00:00 2015-05-01 23:59:59
2 A 10 2015-05-02 00:00:00 2015-05-02 23:59:59
3 A 10 2015-05-03 00:00:00 2015-05-03 23:59:59
4 A 10 2015-05-04 00:00:00 2015-05-04 23:59:59
5 B 10 2015-05-05 00:00:00 2015-05-05 23:59:59
[code]...
View 5 Replies
View Related
Apr 6, 2015
I have 2 tables, one is table A which stores Resources Assign to work for a certain period. The structure is as below
Name StartDate EndDate
Tan 2015-04-01 08:30:00.000 2015-04-01 16:30:00.000
Max 2015-04-01 08:30:00.000 2015-04-01 16:30:00.000
Alan 2015-04-01 16:30:00.000 2015-04-02 00:30:00.000
The table B stores the item process time. The structure is as below
Item ProcessStartDate ProcessEndDate
V 2015-04-01 09:30:10.000 2015-04-01 09:34:45.000
Q 2015-04-01 10:39:01.000 2015-04-01 10:41:11.000
W 2015-04-01 11:44:00.000 2015-04-01 11:46:25.000
A 2015-04-01 16:40:10.000 2015-04-01 16:42:45.000
B 2015-04-01 16:43:01.000 2015-04-01 16:45:11.000
C 2015-04-01 16:47:00.000 2015-04-01 16:49:25.000
I need to select the item which process in 2015-04-01 16:40:00 and 2015-04-01 17:30:00. Beside that I need to know how many resource is assigned to process the item in that period of time. I only has the start date is 2015-04-01 16:40:00 and end date is 2015-04-01 17:30:00. How I can select the data from both tables. There is no need for JOIN, just seperate selections.
Another item process time is in 2015-04-01 10:00:00 and 2015-04-04 11:50:59.
The result expected is
Table A
Name StartDate EndDate
Alan 2015-04-01 16:30:00.000 2015-04-02 00:30:00.000
Table B
Item ProcessStartDate ProcessEndDate
A 2015-04-01 16:30:10.000 2015-04-01 16:32:45.000
B 2015-04-01 16:33:01.000 2015-04-01 16:35:11.000
C 2015-04-01 16:37:00.000 2015-04-02 16:39:25.000
Scenario 2 expected result
Table A
Name StartDate EndDate
Tan 2015-04-01 08:30:00.000 2015-04-01 16:30:00.000
Max 2015-04-01 08:30:00.000 2015-04-01 16:30:00.000
Table B
Item ProcessStartDate ProcessEndDate
Q 2015-04-01 10:39:01.000 2015-04-01 10:41:11.000
W 2015-04-01 11:44:00.000 2015-04-01 11:46:25.000
View 8 Replies
View Related
Aug 16, 2006
I am attempting to write a SQL query that retrieves info processed between two times (ie. 2:00 pm to 6:00 pm) during a date range (ie. 8/1/06 to 8/14/06)... I am new to SQL and am perplexed... I have referenced several texts, but have not found a solution. Even being pointed in the right direction would be greatly appreciated!!
View 6 Replies
View Related
Jun 11, 2014
I have to find the records with in a paricular dates(from date and to date). In some cases @FromDate or @ToDate could be null. in the following query, when i am passing values @FromDate and @ToDate and execute the SP i am getting records which are not in the given range.
SELECT * FROM TABLE P WHERE
CONVERT(VARCHAR(10), P.[FromDate], 101) BETWEEN
CASE When @FromDate IS NULL Then CONVERT(VARCHAR(10),@minFromDate, 101)
ELSE CONVERT(VARCHAR(10), @FromDate, 101) END
AND CASE WHEN @ToDate IS NULL Then CONVERT(VARCHAR(10), @maxToDate, 101)
[Code] .....
View 4 Replies
View Related
Oct 12, 2015
I have a table with the following data:
Type Date Subtype
1 1-1-2015 10
1 5-1-2015 10
1 6-1-2015 10
1 15-1-2015 11
1 20-1-2015 10
[Code] ....
I want to group by the data to the following while saving the first and last date within each type and subtype:
type startdate enddate subtype
1 1-1-2015 6-1-2015 10
1 15-1-2015 15-1-2015 11
1 20-1-2015 22-1-2015 10
1 25-1-2015 28-1-2015 12
2 2-1-2015 5-1-2015 11
2 6-1-2015 7-1-2015 12
2 14-1-2015 20-1-2015 11
2 23-1-2015 30-1-2015 13
I tried several approaches, but I can't fnd a solution to do this with T-SQL.
View 8 Replies
View Related
Jul 31, 2015
I'm trying to move some logic that I have currently within a program and putting it into SQL instead.
My table has the following 3 fields that are of interest to me: StartDate (DateTime), StopDate(DateTime), Length (int)
Length is calculated based on StopDate - StartDate and is expressed to the nearest minute.
What I want to do is query the Db giving a start date and end date and return all records that fall within that date range. I then want to present that data such that the earliest date is set to the start date criteria, the last to the end date criteria and the length recalculated.
Say for example I query for results between 01/02/2015 07:00:00 and 01/02/2015 19:00:00 and I get the following:
Start Stop Length
01/02/2015 06:30:00 01/02/2015 07:05:00 35
01/02/2015 07:05:00 01/02/2015 10:00:00 175
01/02/2015 10:00:00 01/02/2015 19:15:00 555
I would like the output to show as
Start Stop Length
01/02/2015 07:00:00 01/02/2015 07:05:00 5
01/02/2015 07:05:00 01/02/2015 10:00:00 175
01/02/2015 10:00:00 01/02/2015 19:00:00 540
Is there a way to do this?
View 5 Replies
View Related
Dec 3, 2007
Say I want to return only records with dates that fall within the next 6 months. Is there some straight-forward, simple way of doing so?As of now, I'm explicitly giving it a date 6 months in the future, but I'd like to replace it with some sort of function. SELECT DateField1WHERE (DateField1 < CONVERT(DATETIME, '2008-06-03 00:00:00', 102)) Any help is greatly appreciated... btw I'm using SQL 2005.
View 1 Replies
View Related
Aug 19, 2013
I want to get all records that have a valid date range for todays date(20130819).
All records have a date_f and date_t. I need to check that against todays date. The below code is my version of sql pseudo code.
SELECT DISTINCT
p.id,
p.name,
c.ip_number
FROM
tbl_Person AS p, tbl_current_conn_ipnumber AS c
[Code] .....
View 2 Replies
View Related
Aug 20, 2015
Basically, I have a membership table that lists each member with an effective period, Eff_Period, that indicates a month when a member was active. So, if a member is active from Jan to Mar, there will be three rows with Eff_Periods of 201501, 201502 and 201503.
All well and good.But, a member may not necessarily have continuous months for active membership. They might have only been active for Jan, Feb and Jun. That would still give them three rows, but with noncontinuous Eff_Periods; they'd be 201501, 201502 and 201506.There is also a table that logs member activity. It has an Activity_Date that holds the date of the activity - betcha didn't see that comin'. What I'm trying to do is determine if an activity took place during a period when the member was active.
My original thought was to count how many rows a member has in the Membership table and compare that number to the number of months between the MIN(Eff_Period) and the MAX(Eff_Period). If the numbers didn't matchup, then I knew that the member had a disconnect somewhere; he became inactive, then active again. But, then I thought of the scenario I detailed above and realized that the counts could match, but still have a discontinuity.So, is there a nifty little SQL shortcut that could determine if a target month is contained within a continuous or discontinuous list of months?
View 14 Replies
View Related
Jun 16, 2015
I have a situation where an agent has number of activities for a certain date range. If an agent has multiple activities within certain date range, I would like BALANCE BEFORE from the first activity and BALANCE AFTER from the last activity. Here is my current SQL query that returns the following data:
DECLARE @BeginDate Datetime
DECLARE @EndDate Datetime
Set @BeginDate = '05-1-2015'
Set @EndDate = '05-31-2015'
SELECT
a.AgentName,
R.BALANCEBEFORE,
[Code] ....
AGENTNAME BALANCE BEFORE BALANCE AFTER DATE
DOUGLAS 9738.75 9782.75 2015-05-11
DOUGLAS 9782.75 9804.75 2015-05-12
DOUGLAS 9804.75 9837.75 2015-05-13
In the sample data above, ideally I would like my query to return data as follow:
AGENTNAME BALANCE BEFORE BALANCE AFTER
DOUGLAS 9738.75 (from first activity) 9837.75 (from last activity)
Not sure how I can write sql query to accomplish this.
View 7 Replies
View Related
Jul 23, 2015
I am trying to query a code where i need to loop a month in a specified date range. Inside the loop I need to return a result of data each month and need to update the table of the returned data. How do I do the update a field inside the loop? Here's my query:
declare @table1 table (
YEAR_EFF int,
MONTH_EFF int,
IDNumber (8),
SUBS_CNT smallint,
MEM_CNT smallint)
declare @StartDate datetime,
[code]....
Others says I need to use exec sp_executesql N'' but how do I use it using my code above?
View 7 Replies
View Related
Jun 29, 2015
I've data like below:
Now, I've to get active data for a particular date range. Let me explain the active data definition as below:
StartDate : 01-Jul-2015
EndDate : 31-Dec-2015
It should return all the data which was active for that date range even if it was only for one day.If no data found for that date range, check the last record before start date and and if its active then it should be returned else not.
I though of creating a function and pass primary key with date range and return the final status but that doesn't seems like an optimized query.
View 4 Replies
View Related
Jan 15, 2012
If you have a table that has records which are applicable over a date range, is there a preferred design for dealing with the dates?
A simple example might be an employee table, which might have multiple employees, with each employee have multiple records, each record being applicable over a particular date range.
For instance:
Code:
EmpID EmployeeName StartDate EndDate AdditionalFieldsOfData
00001 Jones, Jerry 4/6/2011 8/10/2011
00001 Jones, Jerry 8/11/2011 1/7/2012
00001 Jones, Jerry 1/8/2011 12/31/3000
00002 Fredricks, Fred 8/3/2011 10/15/2011
00002 Fredricks, Fred 10/16/2011 12/31/3000
One could model this table with an implied EndDate (of 12/31/3000), as in:
Code:
EmpID EmployeeName StartDate AdditionalFieldsOfData
00001 Jones, Jerry 4/6/2011
00001 Jones, Jerry 8/11/2011
00001 Jones, Jerry 1/8/2011
00002 Fredricks, Fred 8/3/2011
00002 Fredricks, Fred 10/16/2011
Or, one could imply the beginning date and store the first record's beginning date elsewhere, in a date hired table, or in additional field on each record. As in:
Code:
EmpID EmployeeName EndDate HireDate AdditionalFieldsOfData
00001 Jones, Jerry 8/10/2011 4/6/2011
00001 Jones, Jerry 1/7/2012 4/6/2011
00001 Jones, Jerry 12/31/3000 4/6/2011
00002 Fredricks, Fred 10/15/2011 8/3/2011
00002 Fredricks, Fred 12/31/3000 8/3/2011
View 4 Replies
View Related
Aug 21, 2014
I have two tables, customers and appointments.
I want to bulk insert records for a date range and a day of the week.
For example, John Smith has an appointment on every monday for the next three months. How do I accomplish this?
View 1 Replies
View Related
Mar 11, 2008
Ok, I have two parameters - @StartDate and @EndDate. We only care about the date part of these paramters. What I would like to do is create a table with one record for each date between these two values. For example:
@StartDate = '01/01/2008'
@EndDate = '01/8/2008'
Should yield a table with 9 records in it for every day between @StartDate and @EndDate like so:
01/01/2008 <datacol1> <datacol2>
01/02/2008 <datacol1> <datacol2>
01/03/2008 <datacol1> <datacol2>
01/04/2008 <datacol1> <datacol2>
01/05/2008 <datacol1> <datacol2>
01/06/2008 <datacol1> <datacol2>
01/07/2008 <datacol1> <datacol2>
01/08/2008 <datacol1> <datacol2>
I know I could just do a WHILE (@StartDate <= @EndDate) loop and insert records into a temp table but I'm looking to see if there are any new methods/techniques to achieve this with a more simple statement.
View 3 Replies
View Related
Nov 17, 2015
My scenario is: a person has many events, all based on a date. I need to aggregate the person to show min and max dates for a period, the period being defined as ending when there is not an event following the next date.
DECLARE @Events TABLE
(
PK_EventINTIDENTITY(1,1) PRIMARY KEY
,FK_UserINTNOT NULL
,EventDateDATENOT NULL
)
DECLARE @User TABLE
[Code] ....
I would expect the groups to look something like below:
Is this where a recursive CTE may be used?
View 6 Replies
View Related
Oct 8, 2015
I need to recognize only one month in a date range e to make a proportion of the quantity. Practically, period 31-08-2015 - 30-09-2015 is 31 days, 1 belonging August and 30 belonging September so 3.2258% of the quantity must belong August and 96.7742% September. The quantity 200, so 193.54 belong September (That's what I need to achieve). Range 01-09-2015 / 30-09-2015 Qty 500, all 500 belong September.
Range 01-07-2015 / 20-08-2015 Qty 2500 0 belong September. A little bit more complicated if I got 25-06-2015 / 16-12-2015. it 30 day for September and with a datediff I can count the days and make a proportion. I can write piece by piece the code but I'd prefer of course to have only one query for this.
The DDL:
create table forum (idd int, byfrom date, byto date, qty int)
insert into forum values
(1,'2015-06-15','2015-08-18',300),(2,'2015-09-16','2015-10-04',400),(3,'2015-07-28','2015-09-27',1000),
(4,'2015-09-01','2015-09-30',500),(5,'2015-09-03','2015-09-03',300),(6,'2015-08-02','2015-09-02',100),
(7,'2015-07-01','2015-07-30',500),(8,'2015-06-03','2015-12-08',500),(9,'2015-09-01','2015-09-30',500),
(10,'2015-08-04','2015-09-04',300)
View 14 Replies
View Related
Apr 22, 2014
I've been experiencing difficulty with pulling records using a where clause date range. I'm using this:
select *
from dbo.ACCTING_TRANSACTION_hISTORY
where ath_postype = 'NTC' or ath_postype='NTD' and
ath_postdate >= '2013-01-01 00:00:00' and
ath_postdate <= '2013-01-05 23:59:59'
I've also tried variations of this without the time portion of the ath_postdate field (of type datetime) , but it still seems to be pulling records from 2009, etc.
View 9 Replies
View Related
Nov 6, 2014
creating the missing records in a date/time range.
However, I need to return different groups for each span of records.
here's some data....
aaa1
aaa7
bbb2
bbb5
bbb6
The numbers are the hour of the day.
I need to return
aaa 0 0
aaa 1 1
aaa 2 0
aaa 3 0
...
bbb 0 0
bbb 1 0
bbb 2 1
...
and so on.
I've got a numbers table and I can left join with it but I just get nulls for the missing hours instead of having it as above.....I can't think of a way of repeating the groups for each of the 'missing' hours - other than creating a length insert statement to fill in the gaps....unless that is the only way of doing it.
View 6 Replies
View Related
Oct 7, 2015
how to hard code mention date range in my SP to get expected results in my query 01/01/2012 to 12/31/2012
DECLARE @ACCOUNT AS INT
DECLARE @POSTING_DATE AS DATETIME
DECLARE @FIRST_POSTING_DATE AS DATETIME
SET @POSTING_DATE = {?POSTING_DATE}
SET @ACCOUNT = {?ACCOUNT}
[code]...
View 3 Replies
View Related
Jul 23, 2005
Hi Group!I am struggling with a problem of giving a date range given the startdate.Here is my example, I would need to get all the accounts opened betweeneach month end and the first 5 days of the next month. For example, inthe table created below, I would need accounts opened between'5/31/2005' and '6/05/2005'. And my query is not working. Can anyonehelp me out? Thanks a lot!create table a(person_id int,account int,open_date smalldatetime)insert into a values(1,100001,'5/31/2005')insert into a values(1,200001,'5/31/2005')insert into a values(2,100002,'6/02/2005')insert into a values(3,100003,'6/02/2005')insert into a values(4,100004,'4/30/2004')insert into a values(4,200002,'4/30/2004')--my query--Select *[color=blue]>From a[/color]Where open_date between '5/31/2005' and ('5/31/2005'+5)
View 2 Replies
View Related
Oct 20, 2015
Let's say if the date is 01/01/2015 till 01/01/2016
I want split these dates monthly format wise and then use them in variable in cursors to loop
For an example Monthly date should be 01/01/2015 and 01/31/2015 and use these two values in 2 variables and make a loop until it never ends whole date range which is 01/01/2016
View 2 Replies
View Related
May 11, 2015
I have a column in the table which contains below values
Range
XXXX100
xxxx101
xxxx102
...
xxxx1020
below values are strings. I tried using below query but it does not return all values in the range.
Select * from table where Range Between 'XXXX100' AND 'xxxx1020'
May be in need to extract the number to display the values in given range.
View 4 Replies
View Related
Aug 1, 2006
Hi Folks
Need a little help with a Date Range query;
Im using SQL 2000 and the field is set to datetime
I need to query from now to 30 days ago, its very basic I know...
The field is called - ArtDate
Any help appreciated !
Thanks
View 7 Replies
View Related
Apr 20, 2008
Hi there
I have a FileConsumptionDetail table which has [DataTime] every 30 minutes. Also, I have a schedule table with has range time and with certain condition.
Now I would like to query against these 2 tables what is the best approach to handle to do this due the process load is around 20,000 records. The end of result is sum of the Value1 of FileConsumptionDetail with the relevat schedule. I can probably using cursor and loop the 20,000 records of the data and check one by one whether that value is applied on that schedule table. Overkill .. I guess?
Here's the schema of the tables:
CREATE TABLE [dbo].[tnd_FileConsumptionDetail](
[FileConsumptionDetailID] [bigint] IDENTITY(1,1) NOT NULL,
[FileConsumptionID] [bigint] NULL,
[Time] [datetime] NULL,
[Value1] [decimal](18, 4) NULL CONSTRAINT [DF_tnd_ConsumptionDetail_Value1] DEFAULT ((0)),
[Value2] [decimal](18, 4) NULL CONSTRAINT [DF_tnd_ConsumptionDetail_Value2] DEFAULT ((0)),
[Value3] [decimal](18, 4) NULL CONSTRAINT [DF_tnd_ConsumptionDetail_Value3] DEFAULT ((0)),
[Value4] [decimal](18, 4) NULL CONSTRAINT [DF_tnd_ConsumptionDetail_Value4] DEFAULT ((0)),
[Value5] [decimal](18, 4) NULL CONSTRAINT [DF_tnd_ConsumptionDetail_Value5] DEFAULT ((0)),
[DateCreated] [datetime] NULL CONSTRAINT [DF_UsageDetail_DateCreated] DEFAULT (getdate()),
[LastDateModified] [datetime] NULL CONSTRAINT [DF_UsageDetail_LastDateModified] DEFAULT (getdate()),
[IsActive] [bit] NULL
CREATE TABLE [dbo].[glb_Schedules](
[ScheduleID] [bigint] IDENTITY(1,1) NOT NULL,
[ScheduleGroupID] [bigint] NULL,
[ScheduleTypeID] [int] NULL,
[Name] [varchar](100) COLLATE Latin1_General_CI_AS NULL,
[StartTime] [smalldatetime] NULL,
[EndTime] [smalldatetime] NULL,
[Length] [int] NULL,
[IsMonday] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsMonday] DEFAULT ((0)),
[IsTuesday] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsTuesday] DEFAULT ((0)),
[IsWednesday] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsWednesday] DEFAULT ((0)),
[IsThursday] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsThursday] DEFAULT ((0)),
[IsFriday] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsFirday] DEFAULT ((0)),
[IsSaturday] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsSaturday] DEFAULT ((0)),
[IsSunday] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsSunday] DEFAULT ((0)),
[IsJanuary] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsJanuary] DEFAULT ((0)),
[IsFebruary] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsFebruary] DEFAULT ((0)),
[IsMarch] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsMarch] DEFAULT ((0)),
[IsApril] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsApril] DEFAULT ((0)),
[IsMay] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsMay] DEFAULT ((0)),
[IsJune] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsJune] DEFAULT ((0)),
[IsJuly] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsJuly] DEFAULT ((0)),
[IsAugust] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsAugust] DEFAULT ((0)),
[IsSeptember] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsSeptember] DEFAULT ((0)),
[IsOctober] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsOctober] DEFAULT ((0)),
[IsNovember] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsNovember] DEFAULT ((0)),
[IsDecember] [bit] NULL CONSTRAINT [DF_glb_Schedules_IsDecember] DEFAULT ((0)),
[DateCreated] [datetime] NULL CONSTRAINT [DF_GLB_ScheduleDetails_DateCreated] DEFAULT (getdate()),
[LastDateModified] [datetime] NULL CONSTRAINT [DF_GLB_ScheduleDetails_LastDateModified] DEFAULT (getdate()),
[IsActive] [bit] NULL CONSTRAINT [DF_GLB_ScheduleDetails_IsActive] DEFAULT ((1))
IsMonday - IsSunday is basically a flag for each day if it's a daily type of schedule.
IsJan - isDec is a flag for each month if it's a monthly type of schedule.
Regarding 2nd table design, i am not sure this is a best approach though and I am happy to change if it's easy to query.
Hope this clear and I am appreciated your comment.
Thanks
View 1 Replies
View Related
Mar 7, 2008
Hello,
I have a table called Event, this table has two fields called StartDate and FinishDate. On my application I want the user to be able to search for all the events for a certain date range. I am having some trouble getting my head around the code and was wondering if someone could offer some advice.
Some more details... the user can enter a from date, a to date or both. I can have separate sql code for each situation. The event.startdate and event.finishdate are never null and may contain a time value.
Thanks.
View 9 Replies
View Related
May 14, 2007
Hi,I have a query which works for one day:SELECT SOME_COL AS something, SOME_COL2 AS something2 FROM myTableWHERE DATE = '2007-05-11' AND SOME_STAT 1Returnssomething something 21 23 4How do I get this to work for a date range (e.g. DATE '2007-05-09')where I get:date something something22007-05-09 1 22007-05-09 3 42007-05-10 1 22007-05-10 3 42007-05-11 1 22007-05-11 3 4Thanks in advance!
View 2 Replies
View Related
Nov 4, 2006
I use oledb (ACCESS database) in my application. i want to build a query to retrieve the number of Bookings from my Booking table where the appointment_date_time.timeOfADay is in range of 9am-12pm or 14pm- 7pm, that is (>= 9 and <12) or (>= 14 and < 17). Please help to build the query,
I found some query sample like:
select * from tblstudents where classID='1' and studentstartdate between ('2004-12-03') and ('2004-12-12')
or
WHERE DateField BETWEEN @StartDate AND @EndDate
But I dont want to search year and month and day, i just want to search the actual hour of a day. i am stuck with the syntax, please help
View 1 Replies
View Related
Dec 18, 2001
I need SQL to determine what the date range for the previous month was, ie
Start date 11/01/01 for 11/30/01.
The results will populate a drop down box for user queries.
View 1 Replies
View Related
Jan 22, 2008
hi, i'm using sql sserver 2005 and i have a time that i need to change to a datetime query (from the start of the day to the end of the day), whats the syntax for that? thx
View 9 Replies
View Related