Help with a query please !! It works but needs adjusting !

Hi

I'm using this query with PHP and an Access database. It works well and
returns the results expected..

[code]
strSQL = _
"SELECT * FROM tbl" &_
"WHERE CDATE(Date) = #" & dtOnDay & "# OR Date2 = #" & dtOnDay & "#
OR Date3 = #" & dtOnDay & "# OR Date4 = #" & dtOnDay & "# OR Date5 = #"
& dtOnDay & "# OR Date6 = #" & dtOnDay & "# OR Date7 = #" & dtOnDay &
"#"
[/code]

What I need to do is filter the results..
Currenlty this returns all the results were the date is matched.

But I need to do the above AND this:

WHERE userID = SearchedUsername OR WHERE userID2 = SearchedUsername

HELP !

Thanks
jerryyang_la1 [ Sa, 16 September 2006 16:27 ] [ ID #1468672 ]

Re: Help with a query please !! It works but needs adjusting !

jerryyang_la1 [at] yahoo.com wrote:
> Hi
>
> I'm using this query with PHP and an Access database. It works well and
> returns the results expected..
>
> [code]
> strSQL = _
> "SELECT * FROM tbl" &_
> "WHERE CDATE(Date) = #" & dtOnDay & "# OR Date2 = #" & dtOnDay & "#
> OR Date3 = #" & dtOnDay & "# OR Date4 = #" & dtOnDay & "# OR Date5 = #"
> & dtOnDay & "# OR Date6 = #" & dtOnDay & "# OR Date7 = #" & dtOnDay &
> "#"
> [/code]
>
> What I need to do is filter the results..
> Currenlty this returns all the results were the date is matched.
>
> But I need to do the above AND this:
>
> WHERE userID = SearchedUsername OR WHERE userID2 = SearchedUsername
>
> HELP !
>
> Thanks
>

I really don't know the syntax, dbms or system you are using, but the
following is consistent with your example and performs the required
logic. You didn't ask (or show DDL etc.) but from your example and
requirements your database table is far from 1NF and needs looking at.

"SELECT * FROM tbl" &_
"WHERE ( CDATE(Date) = #" & dtOnDay &
"# OR Date2 = #" & dtOnDay &
"# OR Date3 = #" & dtOnDay &
"# OR Date4 = #" & dtOnDay &
"# OR Date5 = #" & dtOnDay &
"# OR Date6 = #" & dtOnDay &
"# OR Date7 = #" & dtOnDay &
"# )" &
"AND ( userID = #" & SearchedUsername &
"# OR userID2 = #" SearchedUsername &
"# )
Robert Stearns [ So, 17 September 2006 04:59 ] [ ID #1469223 ]

Re: Help with a query please !! It works but needs adjusting !

> I really don't know the syntax, dbms or system you are using, but the
> following is consistent with your example and performs the required
> logic. You didn't ask (or show DDL etc.) but from your example and
> requirements your database table is far from 1NF and needs looking at.
>
> "SELECT * FROM tbl" &_
> "WHERE ( CDATE(Date) = #" & dtOnDay &
> "# OR Date2 = #" & dtOnDay &
> "# OR Date3 = #" & dtOnDay &
> "# OR Date4 = #" & dtOnDay &
> "# OR Date5 = #" & dtOnDay &
> "# OR Date6 = #" & dtOnDay &
> "# OR Date7 = #" & dtOnDay &
> "# )" &
> "AND ( userID = #" & SearchedUsername &
> "# OR userID2 = #" SearchedUsername &
> "# )

Hi Thanks I will try this.

Can you please "You didn't ask (or show DDL etc.) but from your
example and
> requirements your database table is far from 1NF and needs looking at."

CHerers
jerryyang_la1 [ So, 17 September 2006 10:35 ] [ ID #1469225 ]

Re: Help with a query please !! It works but needs adjusting !

jerryyang_la1 [at] yahoo.com wrote:

> > I really don't know the syntax, dbms or system you are using, but the
> > following is consistent with your example and performs the required
> > logic. You didn't ask (or show DDL etc.) but from your example and
> > requirements your database table is far from 1NF and needs looking at.
> >
> > "SELECT * FROM tbl" &_
> > "WHERE ( CDATE(Date) = #" & dtOnDay &
> > "# OR Date2 = #" & dtOnDay &
> > "# OR Date3 = #" & dtOnDay &
> > "# OR Date4 = #" & dtOnDay &
> > "# OR Date5 = #" & dtOnDay &
> > "# OR Date6 = #" & dtOnDay &
> > "# OR Date7 = #" & dtOnDay &
> > "# )" &
> > "AND ( userID = #" & SearchedUsername &
> > "# OR userID2 = #" SearchedUsername &
> > "# )
>
Thanks it worked I just needed to amend it as follows:
Ie:

"AND ( userID = '" & SearchedUsername &
"' OR userID2 = '" SearchedUsername &
"' )"

Nore the ' I have added !
jerryyang_la1 [ So, 17 September 2006 13:00 ] [ ID #1469226 ]
PHP » alt.php.sql » Help with a query please !! It works but needs adjusting !

Vorheriges Thema: It is possible?
Nächstes Thema: Creating FUNCTIONS/PROCEEDURES