Date Query
Jun 19, 2007
Hi all:
I am trying to get data that wasn't used in the last six month. Created_on (date field)
select Category_tree_value, Created_on from workitem
where Created_on (field was used from the last six months)
Created_on format (2005-10-01 00:00:00.000)
Thanking everyone in advance.
Lystra
View 1 Replies
ADVERTISEMENT
Sep 29, 2015
how to write a query to get current date or end of month date if we pass year and month as input
Eg: if today date is 2015-09-29
if we pass year =2015 and month=09 then we have to get 2015-09-29
if we pass year =2015 and month=08 then we have to get 2015-08-31(for previous months we have to get EOMonth date & for current month we have to get current date).
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
Nov 3, 2006
Can someone tell me sql query for filtering date field for current day,not last 24hours but from 00:00 to current time?
View 2 Replies
View Related
Nov 1, 2013
I'm currently using the SQL to find records older than todays date in the SSD_SED field. I'm having to update the date manually each day. Is there a way I can automate this?
AND (SSD_SED < '2013-11-01')order by SSD_SED DESC
View 3 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
Nov 16, 2006
I have the following 4 rows in a table
Company JobNumber BeginDate ModifyDate
1 2 12/12/2005 11/12/2006
1 2 12/12/2005 11/15/2006
2 3 11/12/2005 1/12/2006
2 3 11/12/2005 9/15/2006
The company and Job Number make up the key so yes this table has duplicate keys. My question is how would I return the two keys with the max modify date?
So the results would look like this:
1 2 12/12/2005 11/15/2006
2 3 11/12/2005 9/15/2006
Thanks,
View 2 Replies
View Related
Mar 9, 2007
Good Morning to all
I wrote a query to access some data from sql server ,my query is as follows
strsel = "select * from schedule where sector_id='" & str_sec_id & "' And dep_date = " & bb & ""
bb is the date transferred from the other module
i want to check the dep_date as short date format.because bb is in short date format.
in the above checking i am not getting the query result
please look on this code
Regards
Unni
View 2 Replies
View Related
Apr 10, 2007
I have a single table with the following columns:
rowid (pk)
whenloaded
tablename
records
comments
I want to write a query to get the max(whenloaded) date and then each individual related column corresponding to that date IE. tablename, records, comments
Query I have now - Select a.tablename, max(a.whenloaded) From dbo.table_load_tracking a group by a.tablename
This returns the list that I desire although I am not sure how to add the additional columns and maintain the origional listed max(whenloaded).
I would like to understand the concept behind building a query like this so a detailed explanation would be greatly appreciated.
Thank You,
Fullyii
View 1 Replies
View Related
Apr 7, 2005
I have a table with the following structure: FacilityID, DepartmentID, NumberBeds, DateCreated. I record gets added per FacilityID-DepartmentID. Not every facility and every department within the facility needs to have an entry and there can me multiple entries on the same date. I want to create a pivot table of sorts, which I think I can do, as well as the joins to get the Facility Name and Department Name from other tables.
What I really am having problems figuring out right now is how to pull the last entered date per FacilityID-DepartmentID. Here is a sample of what the data looks like in the database and what I want to pull:
Hospital1 Cardiology 1 4/6/05 4:24 PMHospital1 Critical Care 8 4/6/05 4:24 PMHospital1 Med-Surg 3 4/6/05 4:24 PMHospital1 Pediatrics 0 4/6/05 4:24 PMHospital1 Psychiatry 0 4/6/05 4:24 PMHospital1 Telemetry 0 4/6/05 4:24 PM Hospital1 Cardiology 8 4/7/05 9:04 AMHospital1 Critical Care 6 4/7/05 9:04 AMHospital1 Pediatrics 4 4/7/05 9:04 AMHospital1 Psychiatry 0 4/7/05 9:04 AM
I need to have as output (items in red above):Hospital Card CritCare Med-Surg Peds Psych Telem Last UpdatedHospital1 8 6 - 4 0 - 4/7/05 9:04 AM
I'm truly stumped on this one and any help, examples or links to documentation would be greatly appreciated!
View 1 Replies
View Related
Sep 19, 2001
Hi All
Could someone please give me some guidance , I think I have totally lost it.
I am trying to get an age from a dateofbirth field.
1.This is what I have done :
select datepart(year,getdate())- datepart(year,cast(dateofbirth as datetime))
from table
The values are all correct expect everything that has a year of 1949 or below.
This comes thru as 2049 , 2048 , 2047 etc instead of 1949 etc.
I am converting the dateofbirth field to a datetime as this is orginally a character field.
Why would this be happening?
2.If I use this sort of query :
select dateofbirth , datepart(year,getdate())- substring(dateofbirth,1,2)
from table
I get the right age result but in this format - 1948 , 1951, which could then just use the last two digits for the age.
Would there be a simpler way of doing this?
Thanks in advance
Tanya.
View 4 Replies
View Related
Sep 22, 1999
The user enters in a date which is a varchar type and I'm trying to query the
database for all the birthdays of that date. The problem with SQL server is that when you do a search by the date, it makes a match with the timestamp of 12:00AM. So, if you search by a certain date, it also does a search by the time.
If John's birthday in the database is 'Jan 1 1999 08:00AM' and I use this
Select * from people where birthday = @UserInputDate,
the query returns NOTHING because the defualt time is 12AM and the date on that birthday is 08:00AM.
The only way I can get it to return ALL the birthdays of 1/1/1999 is with this statement:
select * from people where birthdate like 'Jan 1 1999 %:%'
But how do I convert the '1/1/1999' to the Jan 1 1999 format and append '%:%' at the end?
I've tried variations of the following:
select * from people where birthdate like @UserInputDate + ' %:%' but for some
reason that only appends one percentage sign '%:' and not '%:%'
Help!
Angel
View 3 Replies
View Related
Dec 3, 2004
Trying to perform a query where it will return all cases between the current day and the first day of the same month, regardless of whether it is this month or 6 months down the road.
WHERE Response_Flag = '1' AND Begun_By_Id = '" & Session("Emp_Id")& "' AND Begin_Date Between GetDate AND ???????
Any help would be greatly appreciated
Chris
View 1 Replies
View Related
Sep 27, 2005
I have to run a sql query to find out whether an employee has a birthday during the month of September. The date is in the format dd-mmm-yyyy (no time) and no matter what I do I can't get it to give me an answer.
So far I've tried LIKE, BETWEEN, >, <. Appreciate any help.
Thanks.
View 4 Replies
View Related
Nov 24, 2005
how would i query the table with dateid for a particular date
DateID
2005-11-24 14:40:00
select * from tbl1 where dateid like '2005-11-24%' ?
how about date and time like 9-11am of something
View 9 Replies
View Related
Jan 11, 2006
Hi!
I have a DB with this fields:
MID - primary key
EVENT - varchar(2)
EVENT_DATE datetime (format mm/dd/yyyy)
I need to design a query that will pickup records from DB with EVENT = '02' and EVENT_DATE equal or earlier than 18 days from the date the query was executed.
In this example, the query should display these 2 records if ran today:
MID EVENT EVENT_DATE
01 02 12/25/2005
02 02 12/20/2005
But not this:
MID EVENT EVENT_DATE
03 03 12/25/2005
04 02 01/01/2006
Any help will be greatly appreciated.
View 8 Replies
View Related
May 17, 2008
Hi
I have two regarding questions regarding queries involving dates.
I have a number of tables in the database i am using, one of which holds date periods of a financial year so it looks like something below:
DatePeriod:
ID, Begin, End
Jan08,01/01/2008,25/01/2008
Feb08,01/02/2008,29/02/2008
Mar08,03/03/2008,28/03/2008
...
...
The tables actual data begins from Jan07.
Another table shows transactions made, something which looks like:
Transactions:
ID, DateMade, CustomerID, ProductID
22,24/01/2008,111,222
23,27/01/2008,117,222
24,27/02/2008,011,233
...
...
The first query I am trying to do is to perform a count of all transactions made during a financial month period as specified by the user. So i guess I would use a variable such as @month which links to the DatePeriod table. This is what I'm not sure on how to do.
The second query is performing a count of all the transactions made within the last 12 months of the month specified by the user.
Can anyone help with this?
Thanks
View 3 Replies
View Related
Jun 3, 2008
I had data that went in wrong
the date in the db went in as
2008-01-06 08:54:18.000
when it should have been 2008-06-01 08:54:18.000
is there an sql statement that i can run to just change all these records to the reverse - meaning to change the date from 01-06 to 06-01
and 02-06 to 06-02 leaving the time as is.
can someone help me with this?
View 5 Replies
View Related
Nov 19, 2013
I am trying to write a query pulling the last te_event from a table by the latest te_date for a set of records. My query is below
SELECT tickets.t_number, tickets.t_reference,ticket_events.te_event, ticket_events.te_date, FROM ticket_events INNER JOIN
tickets ON ticket_events.te_system_ref = tickets.t_number INNER JOIN
warrants_due ON tickets.t_number = warrants_due.wd_system_ref
[code]...
There are 25,000 tickets in the subquery. I can't work out where to put the MAX (ticket_events.te_date) statement.
View 13 Replies
View Related
Dec 19, 2005
Hello, this is my first time with SQL.
I have a Mysql database of 3 tables
1)CUSTOMER (cust#, name, address, tel#, etc)
2)PRODUCT (prod#, desc, price, etc)
3)BOOKINGS (cust#, prod#, order_date)
I also have an admin page with options to display:
1)all bookings
2)bookings for next 7 days
3)bookings for next 14 days
How do I query the database to show the cust#, prod# and order_date from the BOOKINGS table, and the name, address, price from the CUSTOMER table for the three date options above?
I think I need to join two tables within a SELECT statement but am stuck on how to use todays date in the query.
Many thanks
Clam
View 3 Replies
View Related
Sep 3, 2007
Hi all :),
I am trying to do a query so that i can identify an inactive customer. Now if the customer shopped in Jan 2005 and did not shop in 2006 he/she would be deemed as inactive.I have no idea where to start does any one have any ideas???
View 2 Replies
View Related
Oct 24, 2007
Ive been trying to pull some data from a table by date and time based on todays date but im having a few probs.
i have managed to convert the datetime to just date but im still stuck.
Here is my query
Select DATEADD(dd, 0, DATEDIFF(dd, 0, FILE_DATE_TIME)) as DL_Date, NONE63 As RAcc, REF_1, CUSTOMER_NAME, NONE5 as DOB
From D.dbo.TORY
Where DL_Date = DATEADD(dd, 0, DATEDIFF(dd, 0, getdate()))
i have also tried
Select DATEADD(dd, 0, DATEDIFF(dd, 0, FILE_DATE_TIME)) as DL_Date, NONE63 As RAcc, REF_1, CUSTOMER_NAME, NONE5 as DOB
From D.dbo.TORY
Where DATEADD(dd, 0, DATEDIFF(dd, 0, FILE_DATE_TIME)) = DATEADD(dd, 0, DATEDIFF(dd, 0, getdate()))
Please help
View 3 Replies
View Related
Jan 21, 2008
Afternoon all !!!
Was wondering if somebody could help me am trying to write a sql query, but i'm trying to do is run a searh with a where cluase that only brings back data for the current month. And every other time i run it it will do the same. I know i can use this for results from yesterday "cast(convert(varchar(8),getdate()-1,1) as datetime)"
Any help would be great.
Lee
View 2 Replies
View Related
Mar 3, 2008
Hello folks,
i have one table salestable in which tehre is field -salesdate
in this column sometimes date does not exist..but still i want output of that datecolumn.
id no num salesdate salesquantity
-------------------------------------
1 101 s101 1/1/2008 50.00
2 501 s501 1/5/2008 100.00
3 611 s611 2/3/2008 150.00
so i want results like:
id no num salesdate salesquantity
-------------------------------------
1 101 s101 1/1/2008 50.00
- - - 1/2/2008 -
- - - 1/3/2008 -
- - - 1/4/2008 -
2 501 s501 1/5/2008 100.00
----------------- and so on...
can you help me to wrie this query?
thanks.
View 7 Replies
View Related
Mar 19, 2007
I have a table with a date_created and date_expired and I want to lookat the 15th of each month and every month since the system started andcount up how many accounts were active at each of those points intime.Will have to assume that if there's an expiry date bigger than todaythen that account was active at each of those points in time.Can someone pelase tell me how can I do that?Thanks a lot
View 1 Replies
View Related
Jul 20, 2005
I need a query that will select the closest date.I have to tables Pricing and InventoryItem.tblInventoryItemInventoryItemID <- PkDescriptiontblPricingPricingID <- PkInventoryItemIDPriceEffectiveDateI need to select all the current "prices" for each InventoryItem basedon the Pricing's effective date.select top 1 * from tblPricing join tblInventoryItem ontlbPricing.InventoryItemID = tblInventoryItem.InventoryItemIDWHEREtblPricing.EffectiveDate <= GetDate()This does grab the correct price for a single InventoryItem. But Ineed this query run for all InventoryItem's. I probably need somesort of subquery but I can't figure it out....Thanks....
View 3 Replies
View Related
Jul 20, 2005
I have a master table that has all my accounts in it.In a 2nd table I have update notes per each account, so there aremultiple notes entries for each single ID account in teh first table.How can I get the OLDEST dated entry in teh second table, for everyaccount that's had a not entered into if by joining on the ID of thefirst table?This has been driving me nuts, does that make sense to you?Here:Table 1 FIELDSACCOUNTIDTABLE 2 FIELDSNOTEIDACCOUNTID (Foreign Key)DATE_ENTEREDI need to join those two tables on the ACCOUNTID, but ONLY show the mostrecent date for the record I pull from Table 2, since it's got multipleentries in table 2, it's screwing my query up. Any help/ideas?*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
View 1 Replies
View Related
May 21, 2008
Posted - 05/17/2008 : 07:14:48
Hi
I have two questions regarding queries involving dates.
I have a number of tables in the database i am using, one of which holds date periods of a financial year so it looks like something below:
DatePeriod:
ID, Begin, End
Jan08,01/01/2008,25/01/2008
Feb08,01/02/2008,29/02/2008
Mar08,03/03/2008,28/03/2008
...
...
The tables actual data begins from Jan07.
Another table shows transactions made, something which looks like:
Transactions:
ID, DateMade, CustomerID, ProductID
22,24/01/2008,111,222
23,27/01/2008,117,222
24,27/02/2008,011,233
...
...
The first query I am trying to do is to perform a count of all transactions made during a financial month period as specified by the user. So i guess I would use a variable such as @month which links to the DatePeriod table. This is what I'm not sure on how to do.
The second query is performing a count of all the transactions made within the last 12 months of the month specified by the user.
Can anyone help with this?
Thanks
View 3 Replies
View Related
May 7, 2007
hello everyone
i hope you could help me in this query.
i build a query which you give it a month and a year and after it will calculate the overtime of that month (choosen month & year).
my problem is:
ex: if i pick this date (1) then it will calculate it correctly and will give me the result = 20 that's ok, but if i pick this Date (2) them it will calculate the (1) and (2) and will give me the result = 50.
i don't know what is the problem with my Query i hope you help me with it and i appreciatte it.
my Query:
- from IDbox i will take the ID of the employee.
- month variable which it will take the month that you choose.
- year variable which it will take the month that you choose.
PHP Code:
select sum(Overtime) from Evaluation where EmpID = '" & IDbox.text & "' and Date between '#1/" & month & "/" & year & "#' and '#1/" & month & "/" & year & "#' "
ex: this is an example
----------------------------------------------------------
Date | Overtime
-----------------------------------------------------------
2/2/20005 | 20--------------------(1)
-----------------------------------------------------------
3/2/2005 | 30---------------------(2)
-----------------------------------------------------------
4/4/2005 | 10---------------------(3)
-----------------------------------------------------------
View 3 Replies
View Related
Jul 2, 2006
Hi;I'm here for many hours trying to do this but i couldn't find a way.I have a table whith a field called [DOB], where i have people's date of birth.
Now, i need a SQL query to get people who's birthdays are in between two dates "BUT", what about the year on the date?
I use to do this on Access:
SELECT * FROM Members WHERE DATESERIAL(YEAR(NOW()), MONTH(DOB), DAY(DOB)) BETWEEN @startDate AND @endDate
In the query above the year is not a problem because the DateSerial() function add the current year for all birthdates making it easyer to user parameters like: 06/01/2006 to 06/30/2006
Unfortunately, SQL Server does not support DateSerial() function.
I appreciate any help on this.
Thanks a lot.
View 5 Replies
View Related
Jun 16, 2007
i want to save date using inert query like insert into tablname(field1,f2) values('jan',"& format(system.date.now,"dd/MM/yyyy hh:mm ") so to give error that char will not be converted to date and time.plz help its urgent.the same problem is with select query toooooo.
View 7 Replies
View Related
Dec 11, 2007
I have a table that has a date and time column. I need to do a search on the table by days and will eventually need to do it by hours as well.
I wanted to ask the question that will the performance get better if I create two additional columns one stateing the "Day of Week" and the other stating " Hour of Week". These will have numerical values prepopulated i.e. for Saturday 7, sunday 1, Monday 2 etc etc etc. And for the time , I will have 1 for 1pm-159pm 2 for 2-2:59pm pm 3 for 3-3:59pm etc etc etc
The total number of rows in the table could total half a million, with filtered to by weekf of day may be reduce to being 80,000 or so.
Is the above criteria to add two numeric columns to the table and putting indexes on those two numeric fields is a good solution? and efficinet or just using the datepart functionality with the actual date column and using the week of day and time parameters as the case may be.
Thanks fro your help.
Thanks
View 3 Replies
View Related
Mar 15, 2008
I have a table with date fielde.g. SrNo Date 1 1-MAR-2008 2 3-Mar-2008 3 7-Mar-2008 4 10-Mar-2008 5 15-Mar-2008 I need a query to find out Max date which is less than '8-Mar-2008' . i.e i need single output '7-Mar-2008'anybody helpThanks
View 2 Replies
View Related