Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"ALL" keyword in WHERE clause

Posted on 2001-07-06
3
Medium Priority
?
292 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
[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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

730 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