I have a SQL Server table with client names. I need to select a range of names from this list, but the between clause does not work well
Example; select all names begininng with A up to M
sql statement
select name from mydatabase.dbo.customers where name between 'A%' and 'M%' order by name
The result is a list of names beginning with A and up to L
To get the names beginning with M I need to write the where clause as follows
where name between 'A%' and 'N%'
I also tried :
where name >= 'A%' and name <= 'M%'
The resultant list goes from A to L, it does not show the names beginning with 'M'
What is the solution, please?
BTW, is there a range function in T-SQL, similar to Excel (A:M)?
Rafael Copquin
http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Libre de virus. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html ---
where name >= 'AA%' and name <= 'MZ%'
might do the trick, but make sure you check the edge cases.
On Wed, Aug 8, 2018 at 4:07 PM Rafael Copquin rafael.copquin@gmail.com wrote:
I have a SQL Server table with client names. I need to select a range of names from this list, but the between clause does not work well
Example; select all names begininng with A up to M
sql statement
select name from mydatabase.dbo.customers where name between 'A%' and 'M%' order by name
The result is a list of names beginning with A and up to L
To get the names beginning with M I need to write the where clause as follows
where name between 'A%' and 'N%'
I also tried :
where name >= 'A%' and name <= 'M%'
The resultant list goes from A to L, it does not show the names beginning with 'M'
What is the solution, please?
BTW, is there a range function in T-SQL, similar to Excel (A:M)?
Rafael Copquin
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html ---
How about:
WHERE SUBSTR(name,1,1) BETWEEN "A" and "M"
?
On Wed, Aug 8, 2018 at 4:06 PM, Rafael Copquin rafael.copquin@gmail.com wrote:
I have a SQL Server table with client names. I need to select a range of names from this list, but the between clause does not work well
Example; select all names begininng with A up to M
sql statement
select name from mydatabase.dbo.customers where name between 'A%' and 'M%' order by name
The result is a list of names beginning with A and up to L
To get the names beginning with M I need to write the where clause as follows
where name between 'A%' and 'N%'
I also tried :
where name >= 'A%' and name <= 'M%'
The resultant list goes from A to L, it does not show the names beginning with 'M'
What is the solution, please?
BTW, is there a range function in T-SQL, similar to Excel (A:M)?
Rafael Copquin
http://www.avg.com/email-signature?utm_medium=email& utm_source=link&utm_campaign=sig-email&utm_content=webmail Libre de virus. www.avg.com http://www.avg.com/email-signature?utm_medium=email& utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]
The % will be a wildcard in the Between and the Like queries but it will be that character in "= "
select * from DimBusinessPartners where Name between 'A%' and 'N%' order by Name desc
100000139 5482 RCL N I PALLETS LTD 100000138 5481 RCL N H M CLEANING SERVICES 100001907 3532 RCT N AND D JANITORIAL SERVICES 100003525 5241 RCT MZ SPRING 100000334 7715 RCL MZ BUILDING SERVICE 100003657 5609 RCT MYRON ZUCKER INC 100000161 6256 RAP MYRON CORP 100001906 3531 RCT MYRON 100001905 3530 RCT MYOFFICEPRODUCTS 100001903 3528 RCT MYERS PEST AND TERMITE SERVICES INC
On Wed, Aug 8, 2018 at 3:06 PM Rafael Copquin rafael.copquin@gmail.com wrote:
I have a SQL Server table with client names. I need to select a range of names from this list, but the between clause does not work well
Example; select all names begininng with A up to M
sql statement
select name from mydatabase.dbo.customers where name between 'A%' and 'M%' order by name
The result is a list of names beginning with A and up to L
To get the names beginning with M I need to write the where clause as follows
where name between 'A%' and 'N%'
I also tried :
where name >= 'A%' and name <= 'M%'
The resultant list goes from A to L, it does not show the names beginning with 'M'
What is the solution, please?
BTW, is there a range function in T-SQL, similar to Excel (A:M)?
Rafael Copquin
< http://www.avg.com/email-signature?utm_medium=email&utm_source=link&...
Libre de virus. www.avg.com < http://www.avg.com/email-signature?utm_medium=email&utm_source=link&...
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]