SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist ramone_johnny's Avatar
    Join Date
    Jan 2004
    Location
    Brisbane - Australia
    Posts
    434
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Assistance with SQL Query Please

    Hey guys,
    Im far from an SQL expert, I know the occasional inner join and so on, but for this one I need some help. Code is classic ASP.

    What I currently have is a dropdown onscreen that allows users to show "all advertisements" OR "all with photos".

    Im wanting to know how it would be possible to write this query...?

    DB is MS SQL 2000

    strSQL = "SET DATEFORMAT DMY; SELECT S.* FROM tbladverts AS S WHERE S.adverts_status = 1"

    *** SQL QUERY is constructed in accordance with user dropdown form selections....

    ad_types = Request("ad_types")

    if ad_types = "1" then
    'display ALL ad types ' do nothing
    elseif ad_types = "2" then
    'display ads with photos only
    strSQL = strSQL & " AND ....... *get photos*"
    end if

    Photos are stored in the tblphotos table.

    The relationship is as follows...

    tbladverts -> tblphotos (tblph_advertID - which matches the tbladverts PK)

    How is this doable?

    In english ...

    elseif ad_types = "2" then
    'display ads with photos only
    strSQL = strSQL & " AND get me all ads within the tbladverts table that have a related entry in the tblphotos table"

    Make sense?

    Thanks guys,

    John

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    698
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    strSQL = strSQL & " and s.PK in (select tblph_advertID from tblPhotos)"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •