Solved

SQL Query problems

Posted on 2016-08-30
2
62 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

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 41

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

728 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