Need Help With DateTime Query

Jan 16, 2008

Hey gang, I need a little help creating a Query. I have a table storing info about visitors to our company. The name of the table is "visitors" and it has an "arrivalDate" field and a "departureDate" field. Both of these fields are of DateTime data type and both fields are populated prior to the visitors arrival, neither field will accept a null value. I need to run a report each day to see which visitors are currently on site. I am by no means a SQL expert and I am drawing a blank on how to extract this info??

Entry Example:

name: John Doe
arrivalDate: 1/16/08
departureDate: 1/20/08

So every morning between 1/16/08 and 1/20/08 John Doe must show up on the report

I was trying to do something like this with my code (using todays date):
SELECT name FROM visitors WHERE ((MONTH(arrivalDate) = 1 AND DAY(arrivalDate) >= 15 AND YEAR(arrivalDate) = 2008) AND
(MONTH(departureDate) ?????

View 5 Replies


ADVERTISEMENT

SQL Query: Finding Records Between Datetime Inside Datetime

Mar 17, 2007

Hey :)I'm facing a lot of troubles trying to create a new pause/break-system. Right now i'm building up the query that counts how many records that is inside 2 fields. Let me first show you my table:
ID (int)     |    stamp_start (Type: DateTime)        |      stamp_end (Type: DateTime)           |      Username (varchar)0             |      17-03-07 12:00:00                      |            17-03-07 12:30:00                     |     Hovgaard
The client will enter a start time and a end time and this query should then count how many records that are inside this periode of time.
 Example: The client enter starttime: 12:05 and endtime: 12:35.The query shall then return 1 record found. The same thing if the user enters 12:20 and 12:50.My current query looks like this:SELECT COUNT(ID) AS Expr1 FROM table WHERE (start_stamp <= @pausetime_start) AND (end_stamp >= @pausetime_end)But this will only count if I enter the exact same times as the one inside the table.Any ideas how I can figure this out?Thanks for your time so far :)/Jonas Hovgaard - Denmark

View 2 Replies View Related

Datetime Query?

Jun 30, 2006

Hi,
This is my code:
            SqlCommand getPreviousDateCmd = new SqlCommand("SELECT Top 1 Open_date FROM Counter WHERE (Open_date <= @todays_date) ORDER BY Open_date DESC", myConnection);                        //Get previous date            getPreviousDateCmd.Parameters.AddWithValue("@todays_date", DateTime.Now.ToString("dd/MM/yyyy"));            DateTime previousDateTime = Convert.ToDateTime(getPreviousDateCmd.ExecuteScalar().ToString());
            //previousDate = previousDateTime.ToString("dd/MM/yyyy");            LabelToday.Text = previousDateTime.ToString("dd/MM/yyyy");            //If previous date is same as today's date (Get only date and year)
 
I get a huge unstoppable(?) error message when it converts STRING to DATETIME. What I want to do is get DATETIME object and change the format to "dd/MM/yyyy"
Could someone give me some ideas? Thankx!

View 1 Replies View Related

Datetime In In Sql Query

Sep 13, 2007

Hi
I am trying to write a query involve parameters. For example, the query: 
Select * from myTable
where myDateTime=@dt;
If I run the query, I was asked to enter value for the parameter. The query can be generated, however I can't save it, the error message says: Must declare the variable @dt. When I tried to declare it, the system doesn't support it. I am using SQL Server Managerment Studio 2005.
 I also tried the query without the parameter:
Select * from myTable
where myDateTime=31/07/2007;
But it didn't return record for any datetime format.
Could anyone help please? I just want to get some records filtered by a certain DateTime.
 Claire
 
 

View 2 Replies View Related

Datetime Query

Aug 7, 2005

my database contains 1 field with "datetime" in sql serverhw can i query the database to just compare the date section of that field ??? and not the time

View 2 Replies View Related

Datetime Query

Mar 6, 2005

i am trying to query a datetime column in a db.

e.g. 3/7/2005 4:24:01 AM
My query is below :-
--
select a.date, b.useruri as 'FROM', c.useruri as 'TO',
a.body as 'MESSAGE' from messages as a
inner join
users as b
on a.fromid = b.userid
inner join
users as c
on a.toid = c.userid
where a.date like '%2005-03-01%'
order by a.date

View 3 Replies View Related

Datetime Query

Sep 18, 2007

How to display records between datetime field??

View 7 Replies View Related

Need Help With DateTime Query

Jan 16, 2008

Hey gang, I need a little help creating a Query. I have a table storing info about visitors to our company. The name of the table is "visitors" and it has an "arrivalDate" field and a "departureDate" field. Both of these fields are of DateTime data type. I need to run a report each day to see which visitors are currently on site. For a partial example, I will use today's date of 1/16/08:

SELECT name FROM visitors WHERE ((MONTH(arrivalDate) = 1 AND DAY(arrivalDate) >= 15 AND YEAR(arrivalDate) = 2008) AND
(MONTH(departureDate) ?????

It is the second part of the query that I am having trouble with. Am I going about this all wrong? Is there a way to extract this information when all I know is the persons arrival date, departure date, and the current days date? Any help would be greatly appreciated.

View 5 Replies View Related

Get Max Value By Datetime - In Query

Feb 28, 2008

i have select query :

select indxid, indxname, createddate from outmailtab
where indxname like 'update%'


indxid indxname createddate
----------------------------------------------------------------------
84627 update_sept2007 9/26/2007 10:13:46 AM 2007-09-26 10:14:11.213
84652 update_sept2007 9/26/2007 11:20:29 AM 2007-09-26 11:21:15.947
84675 update_sept2007 9/26/2007 1:18:07 PM 2007-09-26 13:18:47.237
150326 update_Jan2008 1/22/2008 12:32:25 PM 2008-01-22 12:40:48.490
150430 update_Jan2008 1/22/2008 3:33:43 PM 2008-01-22 15:41:24.523

i want output like max row ...

indxid indxname createddate
----------------------------------------------------------------------

84675 update_sept2007 9/26/2007 1:18:07 PM 2007-09-26 13:18:47.237
150430 update_Jan2008 1/22/2008 3:33:43 PM 2008-01-22 15:41:24.523

can anyone tell me how to get it?

i tried like:

select indxid, indxname, max(createddate) from outmailtab
where indxname like 'update%'
group by indxid, indxname

but still its getting me same results..i think because of datetime..date is same for different indxid but time is different for all...so can anyone help me to figure it out with datetime function..

thanks.

View 14 Replies View Related

Help With A DATETIME Query

Jul 20, 2005

Hi,I have a table called Bookings which has two important columns;Booking_Start_Date and Booking_End_Date. These columns are both of typeDATETIME. The following query calculates how many hours are availablebetween the hours of 09.00 and 17.30 so a user can see at a glance how manyhours they have unbooked on a particular day (i.e. 8.5 hours less the timeof any bookings on that day). However, when a booking spans more than oneday the query doesn't work, for example if a user has a booking that startson day one at 09.00 and ends at 14.30 on the next day, the query returns 3.5hours for both days. Any help here would be greatly appreciated.SELECT 8.5 - (SUM(((DATE_FORMAT(B.Booking_End_Date, '%k') * 60 ) +DATE_FORMAT(B.Booking_End_Date, '%i')) - ((DATE_FORMAT(B.Booking_Start_Date,'%k') * 60 ) + DATE_FORMAT(B.Booking_Start_Date, '%i'))) / 60) ASAvailable_Hours FROM WMS_Bookings B WHERE B.User_ID = '16' ANDB.Booking_Status <> '1' AND NOT ( '2003-10-07' <DATE_FORMAT(Booking_Start_Date, "%Y-%m-%d") OR '2003-10-07' >DATE_FORMAT(Booking_End_Date, "%Y-%m-%d") )Thanks for your help

View 1 Replies View Related

SQL Query Question (Datetime)

Nov 7, 2005

Hello ,I have a table field named BookedDateTime and its date type is DateTime. It contains the order booked date and time. I have a query to list all the orders which happens on specific date, no matter what time during the day.Because the BookedDateTime combines the date and time, I cannot get rid of the time. So each time when I do the query , I get nothing. How can I solve the problem?Thanks,

View 1 Replies View Related

SQL DateTime Field Query

May 30, 2006

I was wondering if someone could help me here with some reporting I'm trying to do. For website visits, I currently use getdate() to have SQL insert the date and time of the visit in the table. I was wondering, is there a way to grab just the month from the field? I would like to chart this and I need to group the visits by month. I'm not sure how I would go about filtering just the month out of the entire date and time fields.

View 17 Replies View Related

Datetime Convert Query

May 1, 2008

declare @dt varchar(20)
select count(s.sopnumbe) as orders from sop30300 s
left outer join sop30200 ss
on s.sopnumbe = ss.sopnumbe
where s.itemnmbr=ss.sku and s.soptype = 2 and ss.docdate=@dt

well docdate is datetime and dt is varchar
how can i compare - both?

View 6 Replies View Related

Datetime Picker Query

Apr 1, 2008

Oki, I am a newbie so you got to bare with me here.

I am trying to develop a software where I have to input the datetime picker control. What this datetime picker control should allow user is to pick a date and show the data related to that specific date into the datagrid.

For Example.

Database table - Error Codes has a record feild "error_date". When I run the program it shouldn't show anything on the datagrid. I should be choosing the date from the dtp and then click search and it should show me the data onto the datagrid.

Currently the table shows fine on a datagrid when I run the program, it shows the whole list of data into the datagrid but because there is alot of data in it, it takes me atleast 30mins to find something on it. All I want is the data to be filtered by the date and show it to the datagrid.

Could you please kick start me on this?

Many Thanks

Regards

J

View 8 Replies View Related

How Can I Compare Datetime In A Query???

Jul 4, 2006

I have a table with the following columns

company_Id employee_id logon_time_id logoff_time start_valid_period end_valid_period

Employee's working time should only be counted if it is between start_valid_period and end_valid_period

So, if I have for employee1 from company1

logon_time_id = 04/07/2006 11:00
loggoff_time = 04/07/2006 12:20
start_valid_period = 04/07/2006 12:10
end_valid_period = 04/07/2006 12:30

I should consider 04/07/2006 12:10 as the initial datetime, 04/07/2006 12:20 as the final datetime, and count only 10min of work to him. In code:

if(logon_time_id < start_valid_period) initialDatetime = start_valid_period else initialDatetime = logon_time_id

if(logoff_time < end_valid_period) finalDatetime = logoff_time else finalDatetime = end_valid_period

Is there anyway I can do this in a query, without using a stored procedure with "ifs" and everything else?

Thank you!

View 8 Replies View Related

DateTime Validation Throgh Sql Query

Jun 30, 2006

hai friends,how can i made validation of date time through sql query?
Swati

View 2 Replies View Related

Error In Query--datetime Related

May 21, 2008

Hi y'all I have a problem in my query.This is my querySELECT     dbo.BOS_GL_Workplace.WpszState, Emp2.szName, Emp1.szName AS szEmpName, Emp1.szEmployeeId,                     dbo.BOS_PI_Division.szName AS Divisi, dbo.BOS_PI_Team.szDescription,dbo.BOS_SD_Route.szRouteId, dbo.BOS_SD_Route.szDescription, dbo.BOS_SD_Route.szScheduleId,                    dbo.BOS_SD_RouteItem.szCustId, dbo.BOS_SD_Route.szOpUserId,dbo.BOS_AR_Customer.szCustId ,dbo.BOS_AR_Customer.szName, dbo.BOS_AR_Customer.CustszAddress_1 AS AlamatKirim, dbo.BOS_AR_Customer.szTaxId,                     dbo.BOS_AR_Customer.CustszAddress_1 AS AlamatTagih, dbo.BOS_AR_Customer.CustszCity, dbo.BOS_AR_Customer.CustszZipCode,                     dbo.BOS_AR_Customer.szStatus, dbo.BOS_AR_CustSales.szPaymentTermId, dbo.BOS_AR_CustSales.decCreditLimit,BOS_AR_Customer.dtmStart,BOS_AR_Customer.dtmLastUpdated                    FROM         dbo.BOS_PI_Employee Emp1 LEFT OUTER JOIN                    BOS_PI_Employee Emp2 on Emp1.szSupervisorID = Emp2.szEmployeeID Left outer join                     dbo.BOS_GL_Workplace ON Emp1.szWorkplaceId = dbo.BOS_GL_Workplace.szWorkplaceId LEFT OUTER JOIN                     dbo.BOS_PI_Division ON Emp1.szDivisionId = dbo.BOS_PI_Division.szDivisionId LEFT OUTER JOIN                     dbo.BOS_PI_Team ON Emp1.szTeamId = dbo.BOS_PI_Team.szTeamId LEFT OUTER JOIN                     BOS_SD_Route on Emp1.szEmployeeId = BOS_SD_route.szOPuserId LEFT OUTER JOIN                    BOS_SD_RouteItem on BOS_SD_Route.szRouteId = BOS_SD_RouteItem.szRouteID LEFT OUTER JOIN                    BOS_AR_Customer on BOS_SD_RouteItem.szCustID = BOS_AR_Customer.szCUstID LEFT OUTER JOIN                    BOS_AR_CustSales on BOS_AR_Customer .szCustId = BOS_AR_CustSales.szCustID When I run that query, it was working fine the result was correct. Then I tried to add the where clause, like this:WHERE BOS_AR_Customer.dtmLastUpdated >= '8/1/2006' AND BOS_AR_Customer.dtmLastUpdated <='9/21/2007'And it was also working fine, the result was also correct--pay attention dudes the date format is mm/dd/yyyyThen I try to change the date format to dd/mm/yyyy in the where clause like this (because later I realized that, this is the query that gonna be used):WHERE BOS_AR_Customer.dtmLastUpdated >= '1/8/2006' AND BOS_AR_Customer.dtmLastUpdated <='21/9/2007'The result was an error message saying:"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."Can you tell me whats wrong, please. I appreciate anykinds of help guys, thanks. FYI : I use SQL SERVER 2000 Best Regards.  

View 1 Replies View Related

Select Query Based On Datetime

Feb 12, 2002

I need to select certain rows based on a "datetime" column. I need to select rows from 8am yesterday until 8am today.
In Oracle I would use:
select * from foo where TIMESTAMP >= trunc(sysdate - 1) + 8/24 AND TIMESTAMP < trunc(sysdate) + 8/24.
This would start at 8am yesterday and end at 7:59am today.

How would I do this with T-SQL?

thank you,

Mark
Fiesta_donald@email.com

View 1 Replies View Related

SQL Query Error - Datetime Timestamp??

Oct 3, 2007

So, what's wrong with this datetime syntax to the sql query? I'm getting error here..


Code:


insert into tbl_database_profile
(latest_date, version)
values
(datetime, '1')



The datatype for the field "latest_date" is datetime....

Thanks...

View 3 Replies View Related

Convert Datetime Of Query Otimize.

Mar 30, 2004

Hello All,

In following statement in SQL, Which one should I use and why. My intention to get the record between the date and with style 101.
Which is in following is right one. If I use first('A') then it's little bit slower than second 'B'. So Please suggest me asap.

A.

convert(datetime,convert (nvarchar,Cert_WarehouseDetails.IssuedDateX,101)) <= '3/29/2004')
and
(Cert_WarehouseDetails.IssuedDateX is NOT NULL AND
convert(datetime,Cert_WarehouseDetails.IssuedDateX ,101) <= '3/11/2004')
convert(datetime,convert(nvarchar,Cert_WarehouseDe tails.IssuedDateX,101)) <= '3/12/2004')


B
Instead that Can I use like below, as

(convert(datetime,Cert_WarehouseDetails.IssuedDate X,101) >= '1/1/2004') AND
(Cert_WarehouseDetails.IssuedDateX is NOT NULL AND
convert(datetime,Cert_WarehouseDetails.IssuedDateX ,101) <= '3/11/2004')



Please reply to me asap.


Regards,
M. J.


__________________

View 2 Replies View Related

Datetime Diff Query Syntax

Apr 5, 2006

Hi.I'm trying but not getting correct results.I have two tablesone with app, msg, time(varchar,datetime,varchar)app1 start 2006-04-03 13:33:36.000app1 stuff 2006-04-03 13:33:36.000app1 end 2006-04-03 13:33:36.000app1 start 2006-04-03 13:33:36.000app2 start 2006-04-03 13:33:36.000app2 stuff 2006-04-03 13:33:36.000app2 end 2006-04-03 13:33:36.000app2 start 2006-04-03 13:33:36.000app3 start 2006-04-03 13:33:36.000app2 end 2006-04-03 13:33:36.000app2 start 2006-04-03 13:33:36.000app2 end 2006-04-03 13:33:36.000app2 start 2006-04-03 13:33:36.000app2 end 2006-04-03 13:33:36.000app3 end 2006-04-03 13:33:36.000app1 end 2006-04-03 13:33:36.000and another with dr watson crash info(varchar, datetime)app1 2006-04-03 13:33:36.000app2 2006-04-03 13:33:36.000app1 2006-04-03 13:33:36.000app1 2006-04-03 13:33:36.000app3 2006-04-03 13:33:36.000I'm trying to make a query that will allowme to see what entries in the first tableoccurred wtihin, say, a minute, or maybe 40seconds of any of the entries in the secondtable.I want all the entries in the second table tobe present, so I know it has to be some sortof join, probably an outer join.my syntax is giving me bad results, probablybecause I'm just out of practice.can someone tell me how to put a query togetherso I see the data I'm looking for?ThanksJeffJeff Kish

View 3 Replies View Related

Datetime Problems With A Searching Query

Aug 22, 2006

hi;

i want to get some results for new my stored proce is below;

create Procedure HaberleriGetir

@Kelime varchar(50),

@tarih1 smalldatetime,

@tarih2 smalldatetime,

@KatID int,

@lang char(5)

as

if @lang = 'Hepsi'

select * from Haberler where HKatID = @KatID and Metin like %@Kelime% or Baslik like %@Kelime% and Tarih between @tarih1 and @tarih2

else

select * from Haberler where HKatID = @KatID and lang = @lang and Metin like %@Kelime% or Baslik like %@Kelime% and Tarih between @tarih1 and @tarih2



incorrect near @Kelime....

and i can't get a result between two dates like @tarih1 & @tarih2







View 2 Replies View Related

Format Of DateTime Column In SELECT Query

Dec 19, 2006

I am using SQL2005 and ASP.NET 2.0
I have one column in database called DateTime and it is defined like type datetime.It is formated like: day.month.year hour:minutes:seconds
My question is: I want to get date from Column DateTime in format day.month.year in SELECT query, not in stored procedure.
 thanks

View 3 Replies View Related

SQL Query - DateTime - Percentage Between Two Dates For A Year (Jan. 01 - Dec. 31)

Jan 14, 2008

Hello, I need to find the percentage of a a given contract start and end date for the year given.For example, the contract_start date is 05/08/2000 and the contract_end date is 04/30/2010, of course this will be 100% if you want to find the percentage for year 2008    but if you wanted to find the percentage for year  2010, then the percentage would be something like 42% (appr. 5 months) (b/c it would for year 2010, the contract would be from 01/01/2010 thru 04/30/2010)I need to find the percent from the beginning of the year, to the end.a few examples:    start: 01/01/2007   end: 05/01/2007   if for year: 2007; this is 4 months @33.33%    start: 05/01/ 2006   end: 06/01/2007  if for year: 2007, then 6 months @ 50% (01/01/2007 - 06/01/2007); but if it was for year 2006 then it would be 7 months @ 58% (05/01/2006 thru 12/31/2006)     start: 01/01/2000   end: 03/01/2010 for year: 2008 then 12 months @ 100% Any help would be valued. Thank you! 

View 4 Replies View Related

Datetime Query Issue With C# Stored Procedure

Sep 9, 2007

Ok, i am using the convert function to get the date format from my datetime column. My problem is when C# try's to pull the column name the column name is not sent in the query. When I run the query in the query analyzer the column name is blank in the result window. How can I get the date from the record with out losing the name of my column in the query. My data binding needs the name of the column to bind the data to the drop down list control. Here is the statement:


SQL statement
SELECT DISTINCT convert(datetime, eventDT, 110) FROM tblRecognition

C# code
ddlDateTo.DataSource = _uiCode.Fill.Date();
ddlDateTo.DataTextField = "eventDT";
ddlDateTo.DataBind();


Thank you,

View 2 Replies View Related

Query Performance With DateTime Versus Int Condition

Jul 10, 2007

Good day,



The following query performs acceptably (2 seconds against 126,000,000 rows in the main table):

SELECT Count(*)

FROM

Message1_2_3 INNER JOIN

VDMVDO ON Message1_2_3.VDMVDO_ID = VDMVDO.VDMVDO_ID INNER JOIN

NMEA ON VDMVDO.NMEA_ID = NMEA.NMEA_ID

WHERE

NMEA.NMEA_ID BETWEEN 14000000 AND 14086000 AND

VDMVDO.RepeatIndicator = 0 AND

NMEA.SentenceFormatterID = 'VDM'



When we change the first condition from an Int column to a DateTime as in:

NMEA.TimeDate BETWEEN CONVERT(DATETIME, '2007-07-09 8:30:00', 102) AND CONVERT(DATETIME, '2007-07-09 9:30:00', 102)



the query performance falls to 14 seconds, even though both columns are indexed and a similar number of rows are found. When the select clause changes from a simple Count to a complex Max expression, response time falls to over a minute!



Any thoughs on optimizing the DateTime search would be greatly appreciated...

View 4 Replies View Related

Query Data Based On Moving Datetime.

Feb 5, 2008

I'm trying to query data from a database for a report that looks for the last 2 weeks starting at 10pm, taking a value once every 24 hours. Using

AND DateTime >= DateAdd(wk,-2,GETDATE())

AND DateTime <= GetDate()")
I easily get the last two weeks but the query obviously only grabs the data at the time the query runs. I need to be able to run it any time of the day but only grab the data at 10pm. I'm very new at this so please excuse my ignorance but I could really use some help with this. Thanks very much.

View 4 Replies View Related

Query Problem Involving DateTime Column

Sep 28, 2007



Hi all,

I am quite surprise by getting wrong resultset from a simple query like:


select Order_No from Delivery_Order where cust_id = 5 and do_date >= '6/15/2008' and do_date <= '6/31/2008'

In the database, there are data since the last two years. There is no data beyond today's date, in fact. But when I tried to query for 'Order_No' with specified cust_id within above date range (which data is not in the DB), the result will be the 'Order_No' from '6/15/2007' to '6/31/2007'. Isn't it supposed to return null? simply because there is no such date as 2008 yet in the DB.
Help from anyone is needed. Thanks in advance.

Sha.

View 11 Replies View Related

Query DateTime DataType For Current Or Future Events

Oct 12, 2006

I have a sql server express 2005 database with a table named Events with a column named Date (datetime datatype).  I want a query that will display all rows that are either current or future but not past.  I suspect there is a simple way of doing this.  As a Newbie searching archived threads this is what I have come up with so far.  I determine the number of days from present:SELECT DATEDIFF(day, Date, GETDATE()) AS NumberOfDays FROM EventsThis yields number of days from present with positive numbers in the past and negative numbers in the future.  Thus setting a WHERE clause to <= 0 would limit my results to present or future events.  Something like this:SELECT * FROM EventsWhere DATEDIFF(day, Date, GETDATE()) AS NumberOfDays <= 0The error message states: "Incorrect syntax near the keyword 'AS'"This feels like a clumsy way to approach this problem, but I have to start where I am.Any suggestions on how to proceed will be greatly appreciated.

View 2 Replies View Related

Unknown Datetime Error In Query (Overflow At Runtime)

Aug 2, 2005

Hi all,

I have the following query...

SELECT    Count(*)
FROM        Incidents I
WHERE (Priority = 1)
AND (Time_First_Unit_On_Scene IS NOT NULL)
AND (DateDiff(s, Time_ClockStart, Time_First_Unit_On_Scene) <= 480) 
AND (Response_Date BETWEEN '1-Apr-2004')
AND ('31-Mar-2005 23:59:59')
AND (I.Disposition_ID <> 9 )

...and I get the following error message...

 System.Data.OleDb.OleDbException: Difference of two datetime columns caused overflow at runtime.

... any one know what it could be?

Thanks

Tryst

View 1 Replies View Related

Simple SQL Query (To Neglect Time From DateTime DataType)

Nov 23, 2005

we have a table like thisOrderNo OrderDate1 2005-11-04 01:12:47.00022005-11-19 04:26:54.00032005-11-16 11:03:23.00042005-11-21 15:58:37.00052005-11-24 21:45:04.000what will be the sql query, so that the Result look like this.only to neqlect the time factor from datetime data type .OrderNoOrderDate1 2005-11-0422005-11-1932005-11-1642005-11-2152005-11-24

View 4 Replies View Related

Transact SQL :: Query DateTime Field By Date Range

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

Query On Datetime Field Giving Eroneous Result

Mar 20, 2008

Hi,

I am trying to fetch some data from a table .
I wanted to fetch data for which the order_date is >= 1st january 2005 and order_date< 10th January 2005 and for that I have a query

like
1>



SELECT * FROM SALES_ORDER WHERE


ORDER_DATE >= '01/01/2005' and ORDER_DATE <'10/01/2005'


In this query i am getting result for which the order_date is 2005-05-27 and lots of other data for which my criteria is not matching.
The Order_Date is a datetime field.

If I am use convert function then i am getting the expected result

like
2>
SELECT * FROM SALES_ORDER WHERE
convert (datetime, convert (varchar,ORDER_DATE,101), 101) >= '01/01/2005'
AND
convert (datetime, convert (varchar,ORDER_DATE,101), 101) < '01/10/2005'

Why the first query is not giving me correct result ?

View 4 Replies View Related







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