Interval On A Datetime Column
Feb 13, 2008
Hi, I have a table with 3 columns ( Id int, theValue float , aDate datetime). I want to select the number of rows (count) for which the interval of aDate is less than 7 seconds. Is there a way to achieve that in a single query.
PS: This query will be perform on a dataset, that means that I can't use cursor.
Thanks
Sylvain
View 5 Replies
ADVERTISEMENT
Nov 9, 2007
Hello,
I have something i called a deletelist, inside this list is items that is waiting to be deleted.
The deletelist looks like this:username nvarchar(20),itemtype int,deletedate datetime
The SP that runs once everyday and deletes post is called Data_DeleteFromDeleteList.
Inside of this SP i have afew delete functions like this one:DELETE FROM reg_user WHERE (username = (SELECT username FROM data_deletelist WHERE (deletedate < getdate() AND itemtype = 0)))
Now i want to add a new delete function to this list, this function is to execute a SP when the itemtype occurs, like this:SELECT EXEC [dbo].[Data_CompletlyDeleteAUser] @UserName = username, @QResult = @QResult OUTPUT FROM data_deletelist WHERE (username = (SELECT username FROM data_deletelist WHERE (deletedate < getdate() AND itemtype = 2)))
any idea of how i can rewrite this function so it works??in this SP im not using the @QResult for anything, thats in another SP
At the end of this SP, i just delete all the old records from the deletelist like this,
DELETE FROM data_deletelist WHERE (deletedate < getdate())
View 2 Replies
View Related
Oct 1, 2007
I am currently using the code below to convert data collected in 1 minute intervals to other time intervals (e.g., 5 minute intervals). The code works fine except for one thing. I would like the DateTime value in the new interval to coincide with the end DateTime value of that interval rather than the ceiling DateTime value (the values of Field1 thru Field4 must be extracted from existing data). The problem occurs when there is no data for a particular 1 minute time period. An example might make this more clear (in this case 1 min data is converted to 5 min data).
'2007-09-30T08:01:00'
'2007-09-30T08:02:00'
'2007-09-30T08:03:00'
'2007-09-30T08:04:00'
'2007-09-30T08:05:00'
Above values are used to create a 5 min interval record with
DateTimeValue for this record (in DestTableName) = '2007-09-30T08:05:00'
That's how it should work. However, missing data causes a problem
in the next 5 min time interval.
'2007-09-30T08:06:00'
'2007-09-30T08:07:00'
'2007-09-30T08:08:00'
'2007-09-30T08:09:00'
Missing value at '2007-09-30T08:10:00'
Above values are used to create a 5 min interval record with
DateTimeValue for this record (in DestTableName) = '2007-09-30T08:09:00'
Instead, I want the DateTime value in DestTableName to be '2007-09-30T08:10:00'
The values in Field1 - Field4 in DestTable have to be drawn from existing data; the only 'artificial' data would be the DateTime time value needed to coincide with the time interval.
USE tempdb;
IF OBJECT_ID('#Data') IS NOT NULL
DROP TABLE #Data;
IF OBJECT_ID('#Grouped') IS NOT NULL
DROP TABLE #Grouped;
DECLARE @dtStart datetime, @dtEnd datetime, @dtDivisor integer;
SET @dtStart = '2007-07-01T08:01:00';
SET @dtEnd = '2007-09-30T16:30:00';
SET @dtDivisor = 5
Select
[DateTime],
[Field1],
[Field2],
[Field3],
[Field4],
CEILING(DATEDIFF(minute,@dtStart,[DateTime])/@dtDivisor) Frame
Into #Data
From
[SourceDbName].[SourceSchemaName].[SourceTableName]
WHERE
(convert(varchar, [DateTime],126) BETWEEN '2007/07/01' AND '2007/09/30') AND
(convert(varchar, [DateTime],114) BETWEEN '08:01:00' AND '16:30:00')
Select
Frame,
MAX(t1.[DateTime]) [Max_DateTime],
MIN(t1.[DateTime]) [Min_DateTime],
MAX(t1.[Field2]) AS [Field2],
MIN(t1.[Field3]) AS [Field3]
Into #Grouped
From
#Data t1
Group By
Frame
Select
Opn.[DateTime],
[Field1],
[Field2],
[Field3],
[Field4]
Into
[DestDbName].[DestSchemaName].[DestTableName]
From
( Select
G.[Frame],
G.[Max_DateTime] as [DateTime],
D.[Field1],
G.[Field2],
G.[Field3]
From
#Data D
Join #Grouped G On D.[DateTime] = G.[Min_DateTime] And D.Frame = G.Frame
) as Opn Join
( Select
G.[Frame],
G.[Max_DateTime] as [DateTime],
D.[Field4]
From
#Data D
Join #Grouped G On D.[DateTime] = G.[Max_DateTime] And D.Frame = G.Frame
) as Cls On Opn.Frame = Opn.Frame And Opn.[DateTime] = Cls.[DateTime]
View 5 Replies
View Related
Aug 3, 2015
How can I calculate a DateTime column by merging values from a Date column and only the time part of a DateTime column?
View 5 Replies
View Related
Jul 21, 2014
I'm trying to create a report which will give me a break down of how many unique vehicles have been seen between two dates via a 15 minute interval and what Lane they were seen. My current script looks like this
SELECT l.Name [Name], count(l.Name) Total, p.Created
FROM PlateReads p
inner join Lanes l on p.Lane_ID = l.ID
where LicencePlate in (Select Plate from LPRnet_MelAir_C.dbo.TempVehiclePlates)
group by Name
Name being the Lane they were in and the Total being the amount of times a unique vehicle has been seen and p.Created being the date they were seen (thats what I need the interval powered off)
Ideally the output would look like this
16/03/201408:00 to 08:15Bus Lane 15
16/03/201408:00 to 08:15Elevated Road150
16/03/201408:00 to 08:15Public Pickup75
16/03/201408:15 to 08:30Bus Lane 13
16/03/201408:15 to 08:30Elevated Road120
16/03/201408:15 to 08:30Public Pickup55
All the way to 12/04/2014
I’ve got it so it says Lane and Count just can’t get the interval part
View 5 Replies
View Related
Mar 1, 2015
I am new to this group and to Sql query also. My requirement is the following
I have a table with these values...
colacolb colc cold
16:01 1 2 3
17:01 1 3 4
18:01 5 6 8
16:01 8 2 1
17:01 9 5 1
18:01 3 5 1
16:01 4 6 1
17:01 2 3 5
18:01 8 4 3
Now I want to get the SUM of colb, colc on each interval between 16:01 to 18:01...
View 4 Replies
View Related
Jul 9, 2007
Hi,
I'm inserting a datetime values into sql server 2000 from c#
SQL server table details
Table nameate_test
columnname datatype
No int
date_t DateTime
C# coding
SqlConnection connectionToDatabase = new SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=testdb;Integrated Security=SSPI");
connectionToDatabase.Open();
DataTable dt1 = new DataTable();
dt1.Columns.Add("no",typeof(System.Int16));
dt1.Columns.Add("date_t", typeof(System.DateTime));
DataRow dr = dt1.NewRow();
dr["no"] = 1;
dr["date_t"] = DateTime.Now;
dt1.Rows.Add(dr);
for(int i=0;i<dt1.Rows.Count;i++)
{
string str=dt1.Rows["no"].ToString();
DateTime dt=(DateTime)dt1.Rows["date_t"];
string insertQuery = "insert into date_test values(" + str + ",'" + dt + "')";
SqlCommand cmd = new SqlCommand(insertQuery, connectionToDatabase);
cmd.ExecuteNonQuery();
MessageBox.Show("saved");
}
When I run the above code, data is inserted into the table
The value in the date_t column is 2007-07-09 22:10:11 000.The milliseconds value is always 000 only.I need the millisecond values also in date_t column.
Is there any conversion needed for millisecond values?
thanks,
Mani
View 3 Replies
View Related
Jun 6, 2012
I need to compare the contents of a column.
I have a table with 1 column. Below are the sample contents..
DateInterval
2012-06-01 00:30:00.000
2012-06-01 01:00:00.000
2012-06-01 01:30:00.000
2012-06-01 02:00:00.000
2012-06-01 02:30:00.000
[code]....
as you can see, the records have a 30minutes time interval. i need to create a query to know if there are missing records in the table. so basically the result should be this:
DateInterval
2012-06-01 18:00:00.000
2012-06-01 20:30:00.000
if it is not doable, we can get the nearest record of all missing records like this:
DateInterval
2012-06-01 17:30:00.000
2012-06-01 20:00:00.000
or this:
DateInterval
2012-06-01 18:30:00.000
2012-06-01 21:00:00.000
or this:
DateInterval
2012-06-01 17:30:00.000
2012-06-01 18:30:00.000
2012-06-01 20:00:00.000
2012-06-01 21:00:00.000
View 6 Replies
View Related
Jan 22, 2008
I have a column which Data Type is DateTime the value is looks like 2008-01-18 16:40:39.560if I want to group by this column only compare with yyyy/mm/dd , don't care the TimeHow to write a Sql Query to fit this request?the values in Columns like below2008-01-18 16:40:39.5602008-01-18 16:40:39.5602008-01-18 16:40:39.5602008-01-18 16:40:39.5602008-01-18 17:10:02.8572008-01-18 17:10:37.3732008-01-18 17:10:37.3732008-01-18 17:11:57.1872008-01-18 17:12:22.8102008-01-18 17:13:01.4502008-01-18 17:13:37.1532008-01-18 17:13:52.4502008-01-18 17:14:10.6402008-01-18 17:14:24.6532008-01-18 17:14:41.1532008-01-18 17:15:09.3572008-01-21 14:55:18.560 thank you for your posting .
View 3 Replies
View Related
Jul 16, 2005
Hi All,I faced this strange problem with sql server. I have datetime column and storing value from asp.net. If the user doesnt enter any date, then we dont want any value to be stored in the database. But when we checked SQL Server, it default takes this value "01/01/1900". When users clicks on edit button, this value is fetched from database and stored in front end. I dont want this value to be stored in database if i didnt provide value. But in 1 particular page, there are 5 different date columns. I am not sure about how to go ahead. I tried the following way, but again ended up with same problem.insert into tablename.......values (...., txtFromDate.text, txtToDate.text,....). Since value is not there, '' is sent to database and above said value is stored. i want NULL to be stored in teh database when user didnt specify any value.i didnt encounter this problem in Oracle.appreciate your reply.
View 9 Replies
View Related
Dec 27, 2005
hi, i was wondering how to set default value in the datetime column of the database so that it will enter current date and time if one is not provided when a row is populated. is there a store procedure to do this? or built-in function?
mp
View 3 Replies
View Related
Jun 18, 2001
Hi Guys,
I have to take only time from DateTime column filed value.
Is there any function in SQL Server which will give us time only.
Thanks,
Rau
View 2 Replies
View Related
Jul 21, 2000
I've got have a populated table and I want to convert a datetime column so it lists the date only (without the time component)
I tried to run this as a script, but returns an error:
update <table>
where <column>=convert(datetime,convert(char10),<column>,101))
When I run only this part, it does strip the date of the time component but it becomes a string, and I need this field stored as a datetime field:
convert(char(10),hire_date,101)
I'd appreciate any suggestions :)
View 1 Replies
View Related
Apr 20, 2005
I'm trying to update a datetime column from another datetime column. However, I just want the date transferred to the new column without the time. Any ideas? Thanks for your help.
View 6 Replies
View Related
Aug 3, 2007
I have column that hold datetime , i want to split the column into many columns ex:
column --> 01/01/2007 00:00:00
i want tp split to day month year hour minute second
View 1 Replies
View Related
May 15, 2015
In SQL server I have the column doTableDate set a Datetime.I need extract all rows in on date range and I think use to syntax `Between And` If try this version of query I have in output 889 rows all with date 2014-01-03... but I have other records with date 2014-01-04 in column doTableData...
SELECT
*
FROM
doTable
WHERE
doTableDate BETWEEN CONVERT (
datetime,
[code]....
View 9 Replies
View Related
Mar 27, 2006
hi ppls..
we have sql server 2000 EM. we received daily xml files and we insert into our database.there is one column Date_T having data type datetime.till date we recieved this records from xml as '03/23/2004 12:23:34:956' but due to some duplicate isssue we now want to modified this column to recieve as milliseconds like '03/23/2004 12:23:34:956232' now my point is wheather sql server handle this kind of milliseconds..please help me out as early as possible..
T.I.A
Papillon
View 9 Replies
View Related
Jul 11, 2006
I'm having a hard time getting one of my tables to use a non clustered index that I have on a DateTime column.
A sample version of the table is something like this
CREATE TABLE Appointments
(
ID INT NOT NULL,
AppointmentDate DateTime NOT NULL
)
with a clustered primary key on ID and a nonclustered key on AppointmentDate.
This production table has over 1million rows and the problem I have is this:
If I do a SELECT * FROM Appointments where AppointmentDate >= '20060701' AND AppointmentDate < '20060702' the Non clustered index on the AppointmentDate column works fine. i.e. I'm returning all appointments for the 1st of July.
Now if I run the exact same query using datetime parameters, a Clustered index scan is performed instead of an index seek.
DECLARE @AppDate DateTime
SET @AppDate = '20060701'
SELECT * FROM Appointments WHERE AppointmentDate >= @AppDate and AppointmentDate < DATEADD(day, 1, @AppDate)
Any ideas why it would do this?
View 4 Replies
View Related
Oct 1, 2007
HI friends,
Using SmallDateTime in SQL Table, how can I enforce M/DD/YY format on column of type smalldatetime in SQL ServerDB.
What happening is that SQL convert this to YYYY-MM-DD, when my DTS package brings data to table?
Note : output of DTS package is MM/DD/YY format.
Thanks,
View 5 Replies
View Related
Feb 16, 2008
Hello.
In SQL server 2000 (or 2005) I have a need to query a table for rows with the max date value in a datetime column.
Currently I coded the following to give me a specific date in the column:
...where R.start_time >= '02/15/2008' and R.start_time < DateAdd(day, 1, '02/15/2008')
This gives me the rows with the exact date of 02/15/2008.
So, if I don't want to hard-code the date or pass it as a parameter how can I always get the maximum date back from the query?
Thanks.
Walter
View 6 Replies
View Related
Apr 16, 2008
HOW DO I CONVERT DATA AND TIME COLUMNS TO DATETIME COLUMN.
I HAVE A REQUIREMENT TO FIND OUT THE MAX AND MIN OF DATE AND TIME COLUMNS WHICH ARE TWO SEPARATE COLUMNS ALL TOGETHER.
I HAVE DATA IN COLUMN1 AND TIME IN COLUMN2
HAVE TO CONCATENATE BOTH THE COLUMNS TO GET THE MAX AND MIN TO DATE.
EXAMPLE I TRIED TO DO :
SELECT MIN(convert(datetime, VH_DATETIME,121),
MAX(convert(datetime,VH_DATETIME, 121))
FROM (SELECT TOP 10 INPUT_DATE+INPUT_TIME AS VH_DATETIME FROM ADMINDB.dbo.SSIS_VISIT_HIST) VH
Please help me in resolving this issue. Thank you
View 6 Replies
View Related
Jul 13, 2006
Hello,
I am wondering if someone could help me with formatting datatime column.
Goal - keep column in datatime instead of convert to varchar
Current - '2006-06-21 16:54:33.000'
Wants - '2006-06-21 16:54:33'
Any help is appreciated!
-Lawrence
Code Bits
declare @time datetime
set @time = '2006-06-21 16:54:33.000'
select @time, convert(varchar(255), @time, 20)
View 5 Replies
View Related
Nov 5, 2007
Hi,
I am trying to access a date column up to millisecond precession. So I cast date to as follows:
Code BlockCONVERT(varchar(23),CREATE_DATE,121)
I get millisecond part as a result of query but it€™s €œ000€?.
View 5 Replies
View Related
Dec 16, 2006
Well yeah as the topic says, this is my sql question right now;string date = "2006-11-12"; string sql = "SELECT * FROM spell_of_work WHERE date='{0}'",date);problem is that my date column in the table is datetime and not a date so.. error! i dont know if RLIKE or LIKE can help, wating for a reply!herman
View 11 Replies
View Related
Nov 12, 2007
can anybody tell me how to do a select query on a datetime field where if i have a null value in that column, i need to display a some character.
View 4 Replies
View Related
Jan 24, 2002
Hello everyone, I have searched and seached for an answer to something that I know has to be simple but have been unsuccessful. I appreciate any help...
I am trying to take a char (6) column named col001 and convert it to datetime.
The column is in mmddyy format. I am using SQL 2000, but have available sql 7.0 servers if there is a difference. I expect that I have to write a cursor but have been unable to get the correct syntax. Thanks everyone
View 1 Replies
View Related
Dec 14, 2005
Dears
I'd like to get the recordset of records that do NOT have the written value in datetime type column, for ex.
select * from my_data where its_data not like '%00:00:00%' and its_data >= '2005-05-10' and its_data <='2005-05-12'
or
select * from my_data where its_data not like '00:00:00' and its_data >= '2005-05-10' and its_data <='2005-05-12'
in such command I have all records also with (not desired) time 00:00:00 like 2005-05-11 00:00:00
Who knows the proper syntax?
Rgds
View 2 Replies
View Related
Jun 29, 2005
G'day,
I have a datetime column that holds dates and times like
30/06/2005 1:31:00 PM
How would I find all rows that match a certain date regardless of the time, (IE, select all rows with a date of 30/06/2005 with any time)
Thanks,
Robbo
View 4 Replies
View Related
Jan 21, 2012
Below is my query.Its working great if i remove ,Cast(C.ClassTime as time) as StartDate.But when i use this i get an error as The conversion of a varchar data type to a datetime data type resulted in an out-of-range value My ClassName is a varchar.Whose definition i cant change to DateTime now.But i want to cast it to DateTime.
Code:
Select C.ClassID as Appointment_Id,C.ClassName as Appoitment_Descr,Cast(C.ClassTime as time) as StartDate,C.EndClassTime as EndDate, 'Class' as Type
From Dojo D inner join DojoClass C on D.SchoolID = C.DojoSchoolID
Where D.SchoolID = @DojoID
and C.Days like'%' + @Days + '%'
Union
Select E.DojoEventID as Appointment_Id,E.EventName as Appoitment_Descr , E.EventStartDate as StartDate , E.EventEndDate as EndDate,'Event' as Type
From Dojo D inner join DojoEvent E on E.DojoID = D.SchoolID
Where D.SchoolID = @DojoID and @Date
Between E.EventStartDate and E.EventEndDate
how can i cast it correctly?
View 1 Replies
View Related
Jan 2, 2014
How can I get the hhmmss between 9am to 11am for every date in my datetime column.
I tried:
select datetime from tableA where datetime between '2014-01-03 09:00:00' and '2014-01-31 11:00:00'
But it returns all
datetime
2014-01-31 05:30:00
2014-01-06 09:30:00
2014-01-06 10:30:00
.
.
.
.
View 3 Replies
View Related
Jul 23, 2005
Hello everybody,-------------------------------------------------CREATE TABLE [T1] ([IDX] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,[DateEvt] [datetime] NOT NULL,[Value] [varchar] (10) NOT NULL ,[DataX] [varchar] (10) NULL ,CONSTRAINT [PK_T1] PRIMARY KEY CLUSTERED([IDX]) WITH FILLFACTOR = 90 ON [PRIMARY]) ON [PRIMARY]GOinsert into T1 (DateEvt,Value, DataX) values('2004.10.10 10:00:00','0000000001', 'AAAAAAAAAA')insert into T1 (DateEvt,Value, DataX) values('2004.10.10 10:00:01','0000000002', 'AAAAAAAAAA')insert into T1 (DateEvt,Value, DataX) values('2004.10.10 10:00:02','0000000003', 'AAAAAAAAAA')insert into T1 (DateEvt,Value, DataX) values('2004.10.10 10:01:00','0000000001', 'BBBBBBBBBB')insert into T1 (DateEvt,Value, DataX) values('2004.10.10 10:02:00','0000000001', 'CCCCCCCCCC')insert into T1 (DateEvt,Value, DataX) values('2004.10.10 10:03:00','0000000001', 'DDDDDDDDDD')GO-------------------------------------------------and the question is:In which fastes and best for the preformance way, get the last IDX ofspecified Value.I could do this like this:-------------------------------------------------declare @nIDX numericdeclare @sValue varchar(10)select top 1 @nIDX = IDX from T1where Value = @sValueorder by DateEVT desc-------------------------------------------------But I know, this is not fast (even if I have index on DateEVT field),and I'm quite sure, that there is better way to get this IDX.Anyway, this table can be big (like 20 milions records).I could take the max of IDX, but is it a sure way?Any help? Thanks in advanceMatik
View 1 Replies
View Related
Dec 17, 2007
Hi,I want to update a column typed datetime. My statement is:update 'tablename' set Datum_Ende = '2007-12-17 08:49:04.000' where'columnID_name' = 23250 and 'columndate_Name' = convert(datetime,'17.12.2007 08:08:04')This effects an error. The Server said, the dateTime value is out ofvalid Domain.I have tried various statements like this and i think, the problem isthe blank between date and time.Can someone help me?ThanksThomas
View 2 Replies
View Related
Apr 29, 2015
I want to populate a datetime column on the fly within a stored procedure. Below is the query that I currently have that does same but slows down query performance.
CREATE TABLE #TaxVal
(
ID INT
, PaidDate DATETIME
, CustID INT
, CompID INT
[code]...
Which is the best way to write this query for better performance?
View 2 Replies
View Related