Article View: borland.public.interbase.sql
Article #10965Re: Tricky SQL
From: Wayne Niddery [TeamB]
Date: Wed, 01 Jan 2003 17:03
Date: Wed, 01 Jan 2003 17:03
39 lines
2711 bytes
2711 bytes
"Ronny Bengtsson" <Ronny_Bengtsson@hotmail.com> wrote in message news:Xns92F69DA62D2AFronnybengtssonrobese@207.105.83.65... > > I have needs for a SQL query that use both LIKE with wildcards % and > BETWEEN.or IN > > Example > > Select * FROM Table1 C > WHERE C.PN BETWEEN(LIKE '101%381015%9', LIKE '101%381015%99') The question is what you are actually hoping will be returned from the two LIKE clauses. Are you hoping (for example) that if the first LIKE returns '101A381015B9' then the second will return '101A381015B99' (so that BETWEEN works on a set of such ranges rather than one large range)? If so then I don't see a way to formulate it in a single statement. The two arguments of BETWEEN can each be a subselect (e.g: BETWEEN (SELECT PN FROM...) AND (SELECT PN FROM...), but I don't think that will help you here because in that form each subselect must return exactly one row. The only way to do this in one statement is to have a whole series of Betweens with very specific ranges specified instead of wild cards (likely STARTING WITH could be used in this case: STARTING WITH '101A381015B9'. Another possibility is to first prepare another table to contain the ranges, e.g. it might be called RANGES and contain fields FLD1 and FLD2: '101A381015B9', '101A381015B99' '101G381015M9', '101G381015M99' '101X381015S9', '101X381015S99' Now you can use a join: Select * FROM Table1 C JOIN RANGES R ON C.PN BETWEEN R.FLD1 AND R.FLD2 -- Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com) "Democracy, without that guarantee of liberty, is merely a method of selecting tyrants." - Alan Nitikman
Technical Details
Message-ID:
<3e131ffe$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!proxad.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<Xns92F69DA62D2AFronnybengtssonrobese@207.105.83.65>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114a0e,99de7b04b7abe7f7 X-Google-Attributes: gid114a0e,public X-Google-ArrivalTime: 2003-01-01 09:09:46 PST From: "Wayne Niddery [TeamB]" <wniddery@chaff.aci.on.ca> Newsgroups: borland.public.interbase.sql References: <Xns92F69DA62D2AFronnybengtssonrobese@207.105.83.65> Subject: Re: Tricky SQL Date: Wed, 1 Jan 2003 12:03:20 -0500 Lines: 41 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 209.50.82.158 Message-ID: <3e131ffe$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1041440766 209.50.82.158 (1 Jan 2003 09:06:06 -0800) X-Authenticated-User: wniddery Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!proxad.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail