May 5, 2010 at 2:30 pm
please advice anybody in here
I have select * table_name WHERE condition and condition and DATEDIFF()
in that datediff() function I want to add a function in such a way that it will display select products within 1 hour, is this possible??
May 5, 2010 at 2:36 pm
Try (code taken from BOL)
DATEDIFF(hour, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000');
But you'll have to another condition to make sure the hour difference is only for the current day.
May 5, 2010 at 2:41 pm
Keep it simple, keep it sargeable, keep it fast...
WHERE SomeDateTimeColumn >= DATEADD(hh,-1,GETDATE())
I'd also recommend against using any version of the 23:59:59.xxxxxxx stuff.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 5, 2010 at 2:45 pm
well I dont have time stamp in my table I want to generate resultset using select and providing condition like what happened in last hour
May 5, 2010 at 3:15 pm
Unless you have some indication of time in the table or you run the job once an hour automatically whilst capturing the value of an IDENTITY column as a marker for the start of the next run, then I don't believe it can be done.
Heh... and you don't need to PM me for stuff like this... I get notified and if I have the time, I'll respond.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 5, 2010 at 3:34 pm
thanks, I understand that
May 5, 2010 at 5:02 pm
May 5, 2010 at 11:28 pm
Yes... that would work if there were a date column. The posted problem is quite a bit different... the OP has no date column in his table.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 6, 2010 at 5:31 am
Jeff Moden (5/5/2010)
Unless you have some indication of time in the table or you run the job once an hour automatically whilst capturing the value of an IDENTITY column as a marker for the start of the next run, then I don't believe it can be done.Heh... and you don't need to PM me for stuff like this... I get notified and if I have the time, I'll respond.
I don't have any experience with it, but SQL2K8 contains two new features to capture data changes. From BOL:
SQL Server 2008 provides the following new technologies that application developers can use to track data changes and enable applications to query for only the data that has changed:
* Change data capture
* Change tracking
Maybe worth to look at.
Peter
May 6, 2010 at 6:39 am
I'll have to remember that as one of the things to check on when I install my nice new copy of 2k8 Dev Ed. Thanks, Peter.
Now that I see your suggestion and the requirement, it almost sounds like we might be answering one of "those" interview questions.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 6, 2010 at 7:54 am
That's a nice feature, but it's sad that I'm still using SQL2K5. There are quite a few new features that I get introduced to by looking at many interview questions.
Change data: I read through the MSDN articles a bit, but do not see any mention of where are they stored. It seems the default prune date is 3 days, so doesn't seem like it was designed for storing historical data on a large scale (or are they preventing abuse by making sure you know for how many days you're storing the change store).
May 6, 2010 at 8:37 am
I used one of the column having date and ADDDATE so it works... thanks for reply
May 6, 2010 at 10:22 am
rjv_rnjn (5/6/2010)
Change data: I read through the MSDN articles a bit, but do not see any mention of where are they stored. It seems the default prune date is 3 days, so doesn't seem like it was designed for storing historical data on a large scale (or are they preventing abuse by making sure you know for how many days you're storing the change store).
As far as I've understood, if you enable CDC on a specific table an additional (I'm not sure but probably hidden) table is created which can be accessed through a couple of functions. This table is filled with the changes to the original table taken from the transaction log by some background process. Note that CDC was designed especially to easily capture changed data on a regular basis by an ETL process in a data warehouse environment and not as a feature for storing historical data.
Peter
May 6, 2010 at 12:28 pm
Peter Brinkhaus (5/6/2010)
Note that CDC was designed especially to easily capture changed data on a regular basis by an ETL process in a data warehouse environment and not as a feature for storing historical data.Peter
Seeing from that perspective makes more sense (I missed/didn't notice that). Thanks for that, Peter.
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply