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

x
?
Solved

"ALL" keyword in WHERE clause

Posted on 2001-07-06
3
Medium Priority
?
301 Views
Last Modified: 2008-03-06
Is "All" a keyword in SQL?  I have this WHERE clause:

SELECT T1."Descr" c1, T2."ITMSCP" c2, T2."ITMITM" c3, T2."ITMCBL" c4, T2."ITMSTS" c5, T2."ITMTYP" c6, T2."ITMNME" c7, T2."ITMCRD" c8, T2."ITMPHN" c9, T2."ITMEML" c10, T2."ITMDTE" c11, T2."ITMEDT" c12, T3."ALSCDE" c13, T4."ICTNME" c14, T4."ICTCOD" c15

FROM "ACCOUNT" T1, "KITTRAK"."dbo"."ICTMST1" T4, ("ITMMST1" T2 LEFT OUTER JOIN "dbo"."ALSMST1" T3 on T2."ITMCMP"=T3."ALSCMP" and T2."ITMITM"=T3."ALSITM")

WHERE T2."ITMCMP"=T1."AccountID" and T2."ITMCAT"=T4."ICTCOD" and ('All'=lower ('all') or T2."ITMITM" like 'All%') and T2."ITMSCP" in ('LAN') and T2."ITMEDT">=20010101 and T2."ITMEDT"<=20011231 and T2."ITMCAT" in ('D')

ORDER BY 2 asc, 14 asc, 3 asc, 13 asc


Any ideas?  Can't seem to understand.
0
Comment
Question by:svfafel
3 Comments
 
LVL 32

Accepted Solution

by:
Brendt Hess earned 400 total points
ID: 6260646
In this context - no.  The condition 'All' = lower('all') will never be true.

However, if this query string is built dynamically, I would believe that this is a syntax error.  I would speculate that one of these fields ('All' or 'all') are added to the string on the select statement to handle specific cases of matches, and the syntax is just incorrect.

Examining the selection further, I would say that the 'All' is the variable value, and is used theoretically to indicate that all items are being selected - in this case, the syntax should be:

lower('All') = 'all'

0
 
LVL 3

Expert Comment

by:ibro
ID: 6261572
Agree with bhess1 - your condition ['All'=lower('all') will never be true. You can also optimize some clause in the where clause, so you query can run faster:
T2."ITMCAT" in ('D') will run faster if it written as
T2."ITMCAT"='D'
The same is valid for:
T2."ITMEDT">=20010101 and T2."ITMEDT"<=20011231
It will become:
T2."ITMEDT" between 20010101 and 20011231







0
 

Author Comment

by:svfafel
ID: 6266914
Thanks...much appreciated!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

926 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