Hi,
I need help in constructing a query against my Db I have. The DB I have has
122 Tables and 15 columns in each. I have information in a column in one
table that I need to query with data in a column on another table. In other
words, In Table ad, i have a column called ENTRY_ID that I want to query
against data in the column PUBLISH_DATE in table INSERT.
This is what I have so far.
select a.ad_number,a.entry_date,b.publish_date
from ad a, ad_insert b where a.entry_date = '2004-11-03'and b.publish_date =
'2004-11-04'
I know I have records but the query produces no results so
any help on what I am missing would be greatly appreciated.
On Wed, 3 Nov 2004 20:00:03 -0800, Dave Lugo wrote:
>Hi,
>I need help in constructing a query against my Db I have. The DB I have has
>122 Tables and 15 columns in each. I have information in a column in one
>table that I need to query with data in a column on another table. In other
>words, In Table ad, i have a column called ENTRY_ID that I want to query
>against data in the column PUBLISH_DATE in table INSERT.
>This is what I have so far.
>select a.ad_number,a.entry_date,b.publish_date
>from ad a, ad_insert b where a.entry_date = '2004-11-03'and b.publish_date =
>'2004-11-04'
>I know I have records but the query produces no results so
>any help on what I am missing would be greatly appreciated.
Hi Dave,
The syntax looks okay - if there are matching rows in both tables, they
should show up. Without knowing your table structure and the data that's
in your table, it's hard to get more specific than this. If you need more
specific answers, you'll have to provide more specific information first.
See www.aspfaq.com/5006.
Some general remakrs that might or might not apply to your query:
* The date format 2004-11-03 is ambiguous - do you mean November 3rd or
March 11th? The only date formats that are completely safe to use are:
- yyyymmmdd (for date only - remember: no seperators in this format!),
- yyyy-mm-ddThh:mm:ss (for date plus time - note the capital T),
- yyyy-mm-ddThh:mm:ss.mmm (idem, but including milliseconds).
* I assume that the dates are stored using the datetime datatype. A common
pitfall is to forget that datetimes always include a time component as
well as a date component. If you don't supply the time, SQL Server will
assume midnight as default. The above query is comparing a.entry_date to
'2004-11-03T00:00:00.000' and won't match is a.entry_date is equal to
(e.g.) '2004-11-03T16:45:00.000'. If you want to find all rows with
entry_date 20041103, regardless of the time, use a.entry_date >=
'20041103' AND a.entry_date < '20041104'.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
 
No comments:
Post a Comment