 |
|
 |
|
Next: Progress V8.3D
|
| Author |
Message |
External

Since: Jan 11, 2008 Posts: 51
|
(Msg. 1) Posted: Thu Aug 28, 2008 11:37 am
Post subject: selecting rows by DATETIME without providing the time? Archived from groups: comp>databases>sybase (more info?)
|
|
|
Say I'm looking for all rows with a timestamp field from "Jun 4
2008". Since the timestamp field also contains a time (in this case,
8:08AM), the following doesn't work:
SELECT *
FROM comments
WHERE timestamp - '2008-06-04'
The following, however, does work:
SELECT *
FROM comments
WHERE timestamp > '2008-06-04 0:0:0.000' AND timestamp < '2008-06-05
0:0:0.000'
My question is... if I want to find all entries that take place on a
select day, do I always have to specify a date range or is there a way
to make Sybase figure out that I'm not interested in anything above
and beyond what I put into the query matching? >> Stay informed about: selecting rows by DATETIME without providing the time? |
|
| Back to top |
|
 |  |
External

Since: Nov 19, 2007 Posts: 7
|
(Msg. 2) Posted: Thu Aug 28, 2008 11:25 pm
Post subject: Re: selecting rows by DATETIME without providing the time? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Aug 28, 8:37 pm, yawnmoth wrote:
> Say I'm looking for all rows with a timestamp field from "Jun 4
> 2008". Since the timestamp field also contains a time (in this case,
> 8:08AM), the following doesn't work:
>
> SELECT *
> FROM comments
> WHERE timestamp - '2008-06-04'
>
> The following, however, does work:
>
> SELECT *
> FROM comments
> WHERE timestamp > '2008-06-04 0:0:0.000' AND timestamp < '2008-06-05
> 0:0:0.000'
>
> My question is... if I want to find all entries that take place on a
> select day, do I always have to specify a date range or is there a way
> to make Sybase figure out that I'm not interested in anything above
> and beyond what I put into the query matching?
Yes, specify a date range e.g. for today
where
timestamp>=dateadd(dd,datediff(dd,'20000101',getdate()),'20000101')
and timestamp<dateadd(dd,datediff(dd,'20000101',getdate())
+1,'20000101') >> Stay informed about: selecting rows by DATETIME without providing the time? |
|
| Back to top |
|
 |  |
External

Since: Feb 16, 2008 Posts: 12
|
(Msg. 3) Posted: Fri Aug 29, 2008 12:22 am
Post subject: Re: selecting rows by DATETIME without providing the time? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Aug 28, 11:37 am, yawnmoth wrote:
> Say I'm looking for all rows with a timestamp field from "Jun 4
> 2008". Since the timestamp field also contains a time (in this case,
> 8:08AM), the following doesn't work:
>
> SELECT *
> FROM comments
> WHERE timestamp - '2008-06-04'
>
> The following, however, does work:
>
> SELECT *
> FROM comments
> WHERE timestamp > '2008-06-04 0:0:0.000' AND timestamp < '2008-06-05
> 0:0:0.000'
>
> My question is... if I want to find all entries that take place on a
> select day, do I always have to specify a date range or is there a way
> to make Sybase figure out that I'm not interested in anything above
> and beyond what I put into the query matching?
I have you tried:
WHERE datediff(dd,timestamp,'2008-06-04') = 0
?? >> Stay informed about: selecting rows by DATETIME without providing the time? |
|
| Back to top |
|
 |  |
External

Since: Nov 19, 2007 Posts: 7
|
(Msg. 4) Posted: Fri Aug 29, 2008 1:44 am
Post subject: Re: selecting rows by DATETIME without providing the time? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Aug 29, 9:22 am, ThanksButNo wrote:
> On Aug 28, 11:37 am, yawnmoth wrote:
>
>
>
>
>
> > Say I'm looking for all rows with a timestamp field from "Jun 4
> > 2008". Since the timestamp field also contains a time (in this case,
> > 8:08AM), the following doesn't work:
>
> > SELECT *
> > FROM comments
> > WHERE timestamp - '2008-06-04'
>
> > The following, however, does work:
>
> > SELECT *
> > FROM comments
> > WHERE timestamp > '2008-06-04 0:0:0.000' AND timestamp < '2008-06-05
> > 0:0:0.000'
>
> > My question is... if I want to find all entries that take place on a
> > select day, do I always have to specify a date range or is there a way
> > to make Sybase figure out that I'm not interested in anything above
> > and beyond what I put into the query matching?
>
> I have you tried:
>
> WHERE datediff(dd,timestamp,'2008-06-04') = 0
>
> ??- Hide quoted text -
>
> - Show quoted text -
No, that is a bad idea.
If you use a function on a column (in this case datediff) then an
index on that column can’t be used >> Stay informed about: selecting rows by DATETIME without providing the time? |
|
| Back to top |
|
 |  |
External

Since: Feb 01, 2008 Posts: 7
|
(Msg. 5) Posted: Fri Aug 29, 2008 11:42 am
Post subject: Re: selecting rows by DATETIME without providing the time? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On Aug 29, 1:25 am, PDreyer wrote:
> On Aug 28, 8:37 pm, yawnmoth wrote:
>
>
>
>
>
> > Say I'm looking for all rows with a timestamp field from "Jun 4
> > 2008". Since the timestamp field also contains a time (in this case,
> > 8:08AM), the following doesn't work:
>
> > SELECT *
> > FROM comments
> > WHERE timestamp - '2008-06-04'
>
> > The following, however, does work:
>
> > SELECT *
> > FROM comments
> > WHERE timestamp > '2008-06-04 0:0:0.000' AND timestamp < '2008-06-05
> > 0:0:0.000'
>
> > My question is... if I want to find all entries that take place on a
> > select day, do I always have to specify a date range or is there a way
> > to make Sybase figure out that I'm not interested in anything above
> > and beyond what I put into the query matching?
>
> Yes, specify a date range e.g. for today
>
> where
> timestamp>=dateadd(dd,datediff(dd,'20000101',getdate()),'20000101')
> and timestamp<dateadd(dd,datediff(dd,'20000101',getdate())
> +1,'20000101')- Hide quoted text -
>
> - Show quoted text -
You may also wish to try something like ...
WHERE convert(varchar,timestamp,112) = '2000010'
which may run faster / slower depending on your indexing, ASE version,
phase of the moon, etc.
Incidentally, if you really only care about the "day" portion of the
[small]datetime value, Sybase does support both a DATE and a TIME
value.
They don't seem to be commonly used due to some limitations I suspect
(I seem to recall that getting the data to bcp in is difficult, etc.),
and
of course it makes comparing / adding / subtracting rows with these
(in aggregate) unwieldy, but they are there.
HTH,
Keith >> Stay informed about: selecting rows by DATETIME without providing the time? |
|
| Back to top |
|
 |  |
| Related Topics: | UNION all return two rows - Dear All, I have created two select statments, each produce three lines with this layout: 1st Select: SELECT ID, Part#, Period, Value, Dis, Amt, sum(NetSaleValue) as NetSaleValue, ..
Concatenate multiple rows into a single row - Very Urgent - Can someone please help me out in writing the Sql to concatenate the Text_desc for each code for all the seq_nos in the ascending order of seq_no and load into the target table. Source table : S1 Code Seq_no Text_desc ---------------------------...
running a delete statement that matches multiple rows fail.. - I am having a very strange issue and looking for some ideas on next troubleshooting steps. Summary: running a delete statement that matches multiple rows fails or partially fails to delete those rows. Description: I am running Sybase ASE 15.0.0 and...
Problem with ASE 12.5 Backup Server - Hello everyone !!! My problem: I have recently installed ASE 12.5 on winxp. When I try to make a dump or load with isql or DBArtisan i get this message: "Can't open a connection to site 'SYB_BACKUP'. See the error log file in the SQL Server boot..
Tuning stored procedures - Hi Everyone; We are working on tuning a compact framework mobile application which uses the Sybase iAnywhere 9.0 as the database. Performance of the stored procedures have been really bad. But we are at our wits end trying to find out the Stored.. |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|