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
Solved

"ALL" keyword in WHERE clause

Posted on 2001-07-06
3
270 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:
bhess1 earned 100 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

856 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