Solved

SQL Query problems

Posted on 2016-08-30
2
36 Views
Last Modified: 2016-08-30
My query is suppose to search for "Music" in the fields strEventAbstrace or strEventType within the specified date range but it returns records where strEventAbstrace or strEventType contains "Music" from all dates. What am I doing wrong?

SELECT 
      intEventID
     ,dtmEventDateAndTime AS Date
     ,dtmEventDateAndTime AS Time
     ,strEventAbstract AS [Event Description],"
     ,tEventTypes.strEventType AS [Event Type]
     ,strIsOnsite AS [On Campus]
     ,strTransportationProvided AS Transprotation,monCost AS Cost
FROM tEvents
   "INNER JOIN tEventTypes 
      ON tEvents.intEventTypeID = tEventTypes.intEventTypeID
WHERE      strEventAbstract LIKE '%Music%' 
       OR  strEventType Like '%Music%'
       AND dtmEventDateAndTime >= '08/30/2016’ 
       AND dtmEventDateAndTime <= '09/13/2016’ 
ORDER BY dtmEventDateAndTime

Open in new window

0
Comment
Question by:OhioWoodWright
2 Comments
 
LVL 11

Accepted Solution

by:
Missus Miss_Sellaneus earned 500 total points
ID: 41776915
You need parentheses:

SELECT
      intEventID
     ,dtmEventDateAndTime AS Date
     ,dtmEventDateAndTime AS Time
     ,strEventAbstract AS [Event Description],"
     ,tEventTypes.strEventType AS [Event Type]
     ,strIsOnsite AS [On Campus]
     ,strTransportationProvided AS Transprotation,monCost AS Cost
FROM tEvents
   "INNER JOIN tEventTypes
      ON tEvents.intEventTypeID = tEventTypes.intEventTypeID
WHERE      (strEventAbstract LIKE '%Music%'
       OR  strEventType Like '%Music%')
       AND (dtmEventDateAndTime >= '08/30/2016’
       AND dtmEventDateAndTime <= '09/13/2016’)
ORDER BY dtmEventDateAndTime
0
 
LVL 40

Expert Comment

by:Sharath
ID: 41776948
Also, there are double quotes in your query. Not sure if that is intentional.
SELECT 
      intEventID
     ,dtmEventDateAndTime AS Date
     ,dtmEventDateAndTime AS Time
     ,strEventAbstract AS [Event Description]
     ,tEventTypes.strEventType AS [Event Type]
     ,strIsOnsite AS [On Campus]
     ,strTransportationProvided AS Transprotation,monCost AS Cost
FROM tEvents
   INNER JOIN tEventTypes 
      ON tEvents.intEventTypeID = tEventTypes.intEventTypeID
WHERE     (strEventAbstract LIKE '%Music%' 
       OR  strEventType Like '%Music%')
       AND dtmEventDateAndTime >= '20160830' 
       AND dtmEventDateAndTime <= '20160913'
ORDER BY dtmEventDateAndTime

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now