Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Attempting to select a range of values using wildcard & between or logical operators?

$
0
0

Hi Everyone,

I am in the midst of writing a query to return a range of product BIN LOCATIONS from a warehouse stock levels program.

I know the start and end BIN LOCATIONS for the warehouse, e.g.: Start - #00000, and End - Z10000.

However I cannot hard code these into the program, instead I want my operator to designate the first letter of both the start and end BINS locations, and then hit the 'go button'.

Towards this end I have declared a couple of variables in my SQL, as follows -

declare @strBin varchar(10)
set @strBin = ''
if @strBin = ''
	set @strBin = '#%'

declare @endBin varchar(10)
if @endBin = ''
	set @endBin = 'z%'

My challenge is writing a relevant WHERE clause for my select statement, I have tried the following -

where BINLOCAT.BINLABEL between @strBin and @endBin 
order by BINLOCAT.BINLABEL

Whilst the clause above does not cause any errors, neither does it return any results.

My first thought is that the BETWEEN operator does not accept wildcards. But if this is correct then how do I go about allowing an operator to enter the start, and end BINS without typing the entire BIN string (e.g.: #00000)?

I have tried >= @strBin and <= @endBin, but I am having a similar issue with no errors, and no data returned.

Any help will be greatly appreciated.

Kind Regards,

David



Viewing all articles
Browse latest Browse all 23857

Trending Articles