Professional Web Applications Themes

SQL question. Finding 'sth%' or 'sth%' - ASP

Hi guys I have a data table (master) which contains items with their IDs, Names, Expiry Date etc..Their IDs are unique. Say if I want to find items that have names that starts with "LOVE%' or "CHUNK%', how am I suppose to write the query? I have tried a few queries but always got syntax error. SELECT * FROM master.dbo.master WHERE Names LIKE 'LOVE%' OR Names LIKE 'CHUNK%' SELECT * FROM master.dbo.master WHERE Names = (Names LIKE 'LOVE%' OR Names LIKE 'CHUNK%') SELECT * FROM master.dbo.master WHERE Names LIKE 'LOVE%' UNION SELECT * FROM master.dbo.master WHERE Names LIKE 'CHUNK%' Anything ...

  1. #1

    Default SQL question. Finding 'sth%' or 'sth%'

    Hi guys

    I have a data table (master) which contains items with their IDs, Names, Expiry Date etc..Their IDs are unique.

    Say if I want to find items that have names that starts with "LOVE%' or "CHUNK%', how am I suppose to write the query?

    I have tried a few queries but always got syntax error.

    SELECT * FROM master.dbo.master
    WHERE Names LIKE 'LOVE%' OR Names LIKE 'CHUNK%'

    SELECT * FROM master.dbo.master
    WHERE Names = (Names LIKE 'LOVE%' OR Names LIKE 'CHUNK%')

    SELECT
    * FROM master.dbo.master
    WHERE Names LIKE 'LOVE%'
    UNION
    SELECT * FROM master.dbo.master
    WHERE Names LIKE 'CHUNK%'


    Anything wrong with my queries?
    Last edited by pretzel; September 26th at 01:28 AM.
    pretzel is offline Junior Member
    Join Date
    Sep 2011
    Posts
    2

  2. #2

    Default Re: SQL question. Finding 'sth%' or 'sth%'

    Actually ur first query is correct,
    wt is the error that sql server shows u?
    send error details so dat i can help u.
    Quote Originally Posted by pretzel View Post
    Hi guys

    I have a data table (master) which contains items with their IDs, Names, Expiry Date etc..Their IDs are unique.

    Say if I want to find items that have names that starts with "LOVE%' or "CHUNK%', how am I suppose to write the query?

    I have tried a few queries but always got syntax error.

    SELECT * FROM master.dbo.master
    WHERE Names LIKE 'LOVE%' OR Names LIKE 'CHUNK%'

    SELECT * FROM master.dbo.master
    WHERE Names = (Names LIKE 'LOVE%' OR Names LIKE 'CHUNK%')

    SELECT
    * FROM master.dbo.master
    WHERE Names LIKE 'LOVE%'
    UNION
    SELECT * FROM master.dbo.master
    WHERE Names LIKE 'CHUNK%'


    Anything wrong with my queries?
    alochana9 is offline Junior Member
    Join Date
    May 2011
    Location
    hyderabad
    Posts
    4

  3. #3

    Default Re: SQL question. Finding 'sth%' or 'sth%'

    Hi alochana9

    I think I've got it. Funnily my first query worked again I think I'm seeing the errors when I attempt to string multiple queries.

    Does it mean that whenever I want to insert multiple queries I will always need to put the "OR" criteria in front?

    For example,

    SELECT * FROM master.dbo.master
    WHERE Names LIKE 'LOVE%' OR Names LIKE 'CHUNK%'
    AND Expiry > '01/01/1991'
    AND Price > 100
    AND Quantity < 20

    instead of...

    SELECT * FROM master.dbo.master
    WHERE Expiry > '01/01/1991'
    AND Price > 100
    AND Quantity < 20
    AND Names LIKE 'LOVE%' OR Names LIKE 'CHUNK%'
    pretzel is offline Junior Member
    Join Date
    Sep 2011
    Posts
    2

Similar Threads

  1. Finding the PR of a URL
    By giorgoc in forum Macromedia ColdFusion
    Replies: 0
    Last Post: May 18th, 01:50 PM
  2. finding a file by name
    By joonstar in forum Macromedia ColdFusion
    Replies: 0
    Last Post: April 7th, 09:49 PM
  3. finding upstream
    By Bob McElrath in forum Debian
    Replies: 1
    Last Post: August 6th, 08:10 AM
  4. OT: Finding a job
    By Ray at in forum ASP
    Replies: 2
    Last Post: July 2nd, 12:27 PM
  5. Finding a job
    By Andrew Durstewitz in forum ASP
    Replies: 1
    Last Post: July 1st, 08:54 PM

Tags for this Thread

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139