February 4, 2014 at 11:46 pm
Hi Experts,
I came across a weird issue this morning
while using Between operator am unable to retrieve data that starts with second option,
example am using
select * from USER where vendor between 'N' and 'V'
here i expect to get all the records that has vendor name starting with N,O,P,......U,V
but to my surprise i found am just getting N,O ......,U. am unable to retrieve vendors start with 'V'
when i use between 'N' and 'W' it shows with 'V' also........but not showing vendors with 'W'
so i doubt whether between is considering second option 'V' or not.
Help me with this
Thank you.
February 5, 2014 at 2:23 am
The BETWEEN range ends at 'V'. If you have a vendor with exactly this value then it will be included. Vendors called 'V' + anything else will be excluded because they sort after 'V', outside your range. As an experiment, try BETWEEN 'N' AND 'W', which will return all the vendors beginning with 'V' and any vendors which are just 'W'.
There's another way to collect all the vendors beginning with 'V', and that's to follow it with a character which would sort after the letters, something like BETWEEN 'N' AND 'V'+CHAR(255).
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
February 6, 2014 at 1:04 am
WOW.Thank you Chris
it worked.
February 6, 2014 at 8:41 am
ChrisM@Work (2/5/2014)
The BETWEEN range ends at 'V'. If you have a vendor with exactly this value then it will be included. Vendors called 'V' + anything else will be excluded because they sort after 'V', outside your range. As an experiment, try BETWEEN 'N' AND 'W', which will return all the vendors beginning with 'V' and any vendors which are just 'W'.There's another way to collect all the vendors beginning with 'V', and that's to follow it with a character which would sort after the letters, something like BETWEEN 'N' AND 'V'+CHAR(255).
This is one of those painfully obvious things that I'm embarrassed I didn't know. Thanks, Chris.
February 7, 2014 at 1:52 am
Thanks. There are tons of these little bitty helpful tricks and you will find a good many are covered in Spackle articles by Jeff Moden.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
February 7, 2014 at 6:35 am
This can really reach out to bite you when dates are involved, again sort of obvious but so easy to forget/overlook
February 7, 2014 at 6:49 am
batesview (2/7/2014)
This can really reach out to bite you when dates are involved, again sort of obvious but so easy to forget/overlook
It certainly can - but Jeff Moden has most date issues covered in his Spackle articles too. It doesn't matter how much you think you know, there's always going to be something you've missed. Many of these articles have "added value" (Bingle "lagniappe" to see what I mean) making them very worth while reading material even if you are comfortable with the main topic.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
February 25, 2014 at 10:42 am
I actually didn't know you could use BETWEEN in this way, for (var)char datatypes. And without the wildcard % operator. Groovy.
February 27, 2014 at 3:41 am
Good question and awesome answer by experts.. we should not use between operator in string comparision.. if we then should know the limitation that it will not consider last character string because it could start VA,VB like that and it will be greater than V
i think between is perfect for date data type
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply