I need to find rows using 3 digit area code in phone numbers phone numbers are stored in this format (300-121-0101) in "phone" column. phone 300-121-0101 300-151-0122 333-141-4422 I need a query to input "300" and get first 2 rows. Can somebody help me?
select * from xxxxx where substring(phone,1,3) = yyy where xxxxx is your table name and yyy is your area code. My site, WannaBuddy.com depends on such database trickery. Good luck!
check this out Check this example you can provide the @var as 300 for your input declare @table table (phno varchar(100)) insert into @table values (300457589) insert into @table values (300457589) insert into @table values (305457589) declare @var varchar(100) set @var=300 select * from @table where phno like @var + '%' don't use substring function it will make operation slow. As using function on column will impact not using index of that column on execution plan.