November 24, 2009 at 3:25 am
Can anyone please help I'm a relative novice when it comes to MS SQL.
I need to compare the first 3 characters and last 2 characters and compare that with identical pattern in another field.
Example
Field 1 = XYZ 123
Field 2 = XYZAP 99123
With a resultant match of XYZ123
Thanks
November 24, 2009 at 3:43 am
why don't you use right(fieldname,3) and left(fieldname,3)
November 24, 2009 at 4:42 am
Not sure if this is what you are looking for.
CREATE TABLE #t (varr varchar(50))
INSERT INTO #t values ('XYZAP99123')
INSERT INTO #t values ('XYZAP98123')
INSERT INTO #t values ('XYZAP97123')
INSERT INTO #t values ('XYZAP9997123')
INSERT INTO #t values ('DEFAP97123')
Declare @field1 as varchar(50)
SET @field1 = 'XYZ123'
Select * from #t
where varr like LEFT(@field1, 3) + '%' + Right(@field1, 2)
---------------------------------------------------------------------------------
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply