🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #10979

Re: Tricky SQL

#10979
From: amita
Date: Thu, 02 Jan 2003 05:13
91 lines
4275 bytes
Try

Select * FROM Table1 C
where cast(getSubStr(c.PN,1, 3)||getSubStr(c.PN,5, 4) as Integer)>=1234567
and
cast(getSubStr(c.PN,1, 3)||getSubStr(c.PN,5, 4) as Integer)<=1234599

where getSubStr is a UDF to get the substring

--
Amita
Agnisoft
www.agnisoft.com
"Ronny Bengtsson" <Ronny_Bengtsson@hotmail.com> wrote in message
news:Xns92F6EC38DAE0Cronnybengtssonrobese@207.105.83.65...
> Wayne,
>
> This is what I want to do.
>
> I have a database with documents of modifications that could affect
> different part numbers that I have in my inventory.
>
> The issuer of the document could say the the modification will affect a
> range of partnumbers
> i.e. 123-4567 to 123-4599
>
> I want to check my inventory database if I have partnumbers within this
> range.
> But the partnumbers in the inventory database could be previous entered
> and saved in different ways i.e. 123/4567, 123-4568, 123 4590 etc.
>
> Thats why I have the needs for both the LIKE and BETWEEN clauses.
> to find the range of partnumbers regardless of how they are entered in
> the database as long the partnumbers have the tokens at the same place..
>
>
> In my example above my query should give me the 3 partnumbers above as
> they are in the range 123-4567 to 123-4599.
>
> /Ronny
>
>
>
> "Wayne Niddery [TeamB]" <wniddery@chaff.aci.on.ca> wrote in
> news:3e131ffe$1@newsgroups.borland.com:
>
> > "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: <3e13c922@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <Xns92F69DA62D2AFronnybengtssonrobese@207.105.83.65> <3e131ffe$1@newsgroups.borland.com> <Xns92F6EC38DAE0Cronnybengtssonrobese@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 21:10:01 PST
From: "amita" <amita@agnisoft.com>
Newsgroups: borland.public.interbase.sql
References: <Xns92F69DA62D2AFronnybengtssonrobese@207.105.83.65> <3e131ffe$1@newsgroups.borland.com> <Xns92F6EC38DAE0Cronnybengtssonrobese@207.105.83.65>
Subject: Re: Tricky SQL
Date: Thu, 2 Jan 2003 10:43:25 +0530
Lines: 93
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 203.195.196.78
Message-ID: <3e13c922@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1041484066 203.195.196.78 (1 Jan 2003 21:07:46 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail