Click here to Skip to main content
15,892,965 members

Comments by tpkpradeep (Top 13 by date)

tpkpradeep 2-Dec-15 7:40am View    
hi OriginalGriff
how about this..

select dup1.name1,dup1.tab1,dup1.dist
from
(
select t.rk
from
(
SELECT t1.name1 tab1,t2.name1,dense_rank() over (order by t1.name1) as rk
FROM #tmp_dup t1
inner join #tmp_dup t2 on t1.name1 = t2.name2 and t1.name2 = t2.name1
AND t1.Name1 NOT IN (SELECT name2 FROM #tmp_dup WHERE name2=t1.name1 AND name1 = t2.name2)
group by t1.name1,t2.name1
) as t
group by t.rk
having count(t.rk) = 1
) as dup
left outer join
(
SELECT t1.name1 tab1,t2.name1,dense_rank() over (order by t1.name1) as rk,t1.dist
FROM #tmp_dup t1
inner join #tmp_dup t2 on t1.name1 = t2.name2 and t1.name2 = t2.name1
AND t1.Name1 NOT IN (SELECT name2 FROM #tmp_dup WHERE name2=t1.name1 AND name1 = t2.name2)
group by t1.name1,t2.name1,t1.dist
) as dup1 on dup.rk = dup1.rk
tpkpradeep 1-Dec-15 15:26pm View    
:) I know..,

I tried this

with cte as(
select name1,name2,
row_number() over
(
order by name1,name2
) as cnt
from
#tmp_dup
group by name1,name2
)


select t1.name1,t1.name2,t1.rk
from
(
select a.name1,a.name2,a.cnt as cnt,
dense_rank() over (order by a.name1) as rk
from cte a
where exists(
select 1 from cte b where a.name1 = b.name2 and a.name2 = b.name1)
) t1
group by t1.name1,t1.name2,t1.rk


i got output as below

name1 name2 rk
BG CH 1
CH BG 2
CH HY 2
HY CH 3

but i got strucked removing the value 2
tpkpradeep 1-Dec-15 14:22pm View    
I'd probable create an SQL function which took the two names, and returned a composite name that was ordered, so the BG, CH returned the same value as CH, BG

How can i perform this? I tried in different ways but i couldn't.., help me this.., please
tpkpradeep 1-Dec-15 14:21pm View    
well good question.. :) customers of different type.., :)
tpkpradeep 10-Aug-15 6:19am View    
DECLARE @TID CHAR(2)
SET @TID = 'ON'

WHERE @TID = (CASE WHEN C.TID IS NULL OR C.TID = '' THEN C.TTID
WHEN R.TID IS NULL THEN U.TID ELSE R.TID END)

Sorry I forgot to add the above.