SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: SQL query prob

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    5
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL query prob

    Hi,

    May I know how can I get a proper query for this requirement :

    SELECT * FROM Table WHERE columnA = 1 AND columnB =($A || $B || $C || $D )
    $A,$B,$C and $D are values posted by user. If any of those variables have nothing inside/no value, it will not be included in the query.

    E.g : If $(c == "") . the query will be
    *SELECT * FROM Table WHERE columnA = 1 AND columnB =($A || $B || $D )

    I tried conditional statement to accomplish this but failed. Some guru please advise on this. Thank you.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Ronan View Post
    $A,$B,$C and $D are values posted by user. If any of those variables have nothing inside/no value, it will not be included in the query.
    you will do the exclusion with php logic

    the mysql portion of your question is easy --
    Code:
    ... columnB IN ( $A,$B,$C,$D )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    5
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An error displayed :
    #1271 - Illegal mix of collations for operation ' IN '

    SELECT * FROM cd WHERE week IN ('Te','Tev','Yed')

    Please advise.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    no idea, sorry

    perhaps you could do a SHOW CREATE TABLE, and a collation specialist will be able to help you
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like to know about SQL Server.

    Anushka


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
  •