Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SImple Query Error

Status
Not open for further replies.

michaela18

Technical User
Sep 9, 2009
37
US
I am a beginner to SQL and I have this simple error with this select statement. I am getting an error at the From line but I put in the right name of the database. Any ideas?

SELECT COUNT (CASE WHEN CODE LIKE '%123%'
OR CODE LIKE '%124%'
THEN CODE
END) AS Twenty_MB,
COUNT (CASE WHEN CODE LIKE '%125%'
OR CODE LIKE '%126%'
THEN CODE
END) AS Seventy_MB,
FROM history.dbo.orders
WHERE date = '20100301'
AND package IN ('fulfilled', 'InProcess')
AND code IN ('abc', 'def', 'ghi')
 
You have a comma at the end of the line immediately before the FROM line. SQL Server thinks you want to add another column (to the select), but it found a FROM instead. Remove the comma.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I'm also going to suggest that anytime you need to do a query like this where you are pulling some code out from the middle of a field, then you need to rededign your database. These codes should be separated out and stored in their own indexed field at the time of insert of the data.

Also since your where clause filters on specific codes which are not the codes in the case statements (although they appear to reference the same field), I don't think you are going to get correct results.

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top