Andy Dufresne
2013-09-13 11:52:07 UTC
In MSSQL 2008 R2:
create table mytable(
id (bigint),
productname(nvarcharmax),
productcode(nvarcharmax)
)
select id,productname,productcode
from mytable
where productcode like '12345a'
will return:
id,productname,productcode
2121,super cleaner,12345a
Is it possible to include slight variations of that productcode so that it returns any other record where the value differs by one character?
Example, can I get it to also return productcode = 19345a or 12335a?
id,productname,productcode
2121,super cleaner,12345a
4321,really good cleaner,19345a
4343,wow cleaner,12335a
I don't care what the postion of the differing values are, so 12375a, 42345a, 12342a, 123455, 11345a, etc would all be acceptable.
I want all records "where productcode like '12345a'"
productcode will always have a length of 6 characters (i.e. '12345a7' or '123456a' is not valid).
I suppose I'm looking for something like a regexp for sql. Can this be done?
Thanks
create table mytable(
id (bigint),
productname(nvarcharmax),
productcode(nvarcharmax)
)
select id,productname,productcode
from mytable
where productcode like '12345a'
will return:
id,productname,productcode
2121,super cleaner,12345a
Is it possible to include slight variations of that productcode so that it returns any other record where the value differs by one character?
Example, can I get it to also return productcode = 19345a or 12335a?
id,productname,productcode
2121,super cleaner,12345a
4321,really good cleaner,19345a
4343,wow cleaner,12335a
I don't care what the postion of the differing values are, so 12375a, 42345a, 12342a, 123455, 11345a, etc would all be acceptable.
I want all records "where productcode like '12345a'"
productcode will always have a length of 6 characters (i.e. '12345a7' or '123456a' is not valid).
I suppose I'm looking for something like a regexp for sql. Can this be done?
Thanks