Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Query problems

Posted on 2016-08-30
2
Medium Priority
?
66 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 12

Accepted Solution

by:
Missus Miss_Sellaneus earned 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

971 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