July 25, 2005 at 10:01 am
can some one help me i hate a table that has a matched pair number
ie..
icqrm006520050406142936mxfs100100985-ddpgw000020041209004511mxfs100088798
icqrm006520050406142936mxfs100100995-ddpgw000020041209004512mxfs100088328
icqrm006520050406142936mxfs100100995-icqrm006520050406142936mxfs100100995
and im trying to make a new table that has a procedure to go throught that original table and search if the left side of the dash is = to the right side of the dash and if it is exclude that from the info sent into the new table i want to create...if anyone can help it would be appreciated
July 25, 2005 at 10:27 am
charindex can help you find the positions of the dash and the =. substring can then extract that part out and you can use that for the comparison.
Look them up in BOL and practice.
July 25, 2005 at 10:35 am
--Create temp table to test out the query
Create table temp (pk int identity, Test1 varchar(100))
-- Insert into the Temp Table
insert into temp (test1)
Select 'icqrm006520050406142936mxfs100100985-ddpgw000020041209004511mxfs100088798'
Union All
Select 'icqrm006520050406142936mxfs100100995-ddpgw000020041209004512mxfs100088328'
Union All
Select 'icqrm006520050406142936mxfs100100995-icqrm006520050406142936mxfs100100995'
-- Run the Test query
select *
from Temp
where substring(Test1,1,charindex('-', Test1)-1) <> substring(Test1,charindex('-', Test1) +1, 100)
-- Results
--pk,Test1
1,icqrm006520050406142936mxfs100100985-ddpgw000020041209004511mxfs100088798
2,icqrm006520050406142936mxfs100100995-ddpgw000020041209004512mxfs100088328
drop table Temp
July 25, 2005 at 10:53 am
Ray M the only problem i have is that i have a huge db and i dont' want to have to type in the pairs....
July 25, 2005 at 12:15 pm
This is only for a demo... just use this code and use the right table/column names :
select *
from dbo.Temp
where substring(Test1,1,charindex('-', Test1)-1) substring(Test1,charindex('-', Test1) +1, 100)
July 25, 2005 at 1:41 pm
thanks that worked
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply