Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mayerl
Yak Posting Veteran
95 Posts |
Posted - 2010-06-21 : 11:17:48
|
Morning,I've been asked to find out in our part number convention which part numbers are the same but the rev #'s are different.I've got this so far: select material,LEFT(material, PATINDEX('% R%', material))PartNumber,SUBSTRING(material,PATINDEX('% R%', material),20)Revfrom Materialwhere Material like '%REV%'order by MaterialThat gives me this:0032460-000 REV AE 0032460-000 REV AE0050466-000 REV AJ 0050466-000 REV AJ0110115-000 REV AE 0110115-000 REV AE0110115-000 REV AF 0110115-000 REV AF0110116-000 REV AE 0110116-000 REV AE0110116-000 REV AF 0110116-000 REV AF054-716800 REV C 054-716800 REV C10010017 REV A 10010017 REV A10010026 REV A 10010026 REV A10020001 REV A 10020001 REV A10020002 REV A 10020002 REV A10020003 REV 2 10020003 REV 210020003 REV A 10020003 REV A10020004 REV 1 10020004 REV 110020004 REV A 10020004 REV A10020005 REV 2 10020005 REV 210020005 REV A 10020005 REV A10020006 REV 1 10020006 REV 1 I think there is going to be some kind of subquery involved but any thoughts would be great.ThanksLaura |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2010-06-21 : 11:50:07
|
| What are the desired results? Are you trying to eliminate the part numbers that only have a single rev?=======================================A couple of months in the laboratory can save a couple of hours in the library. -Frank H. Westheimer, chemistry professor (1912-2007) |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-21 : 11:54:19
|
[code]select m.* from Material mjoin( select LEFT(material, PATINDEX('% R%', material)) PartNumber from Material where Material like '%REV%' group by LEFT(material, PATINDEX('% R%', material)) having count(*) > 1)dton dt.PartNumber = LEFT(m.material, PATINDEX('% R%', m.material))order by m.Material[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
mayerl
Yak Posting Veteran
95 Posts |
Posted - 2010-06-21 : 12:02:29
|
Nice. I had worked out something similar.select distinct list1.Part# from ( select LEFT(a.material, PATINDEX('% R%', a.material))Part#, SUBSTRING(a.material,PATINDEX('% R%',a.material),20)Rev# from Material a where a.Material like '%REV%') list1inner join (select LEFT(a.material, PATINDEX('% R%', a.material))Part#, SUBSTRING(a.material,PATINDEX('% R%',a.material),20)Rev# from Material a where a.Material like '%REV%') list2on list1.Part# = list2.Part#where list1.Rev# <> list2.Rev#order by list1.Part#But your is more elegant.ThanksLaura |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-21 : 12:04:55
|
 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2010-06-21 : 16:09:07
|
| What are the desired results? Are you trying to eliminate the part numbers that only have a single rev?=======================================A couple of months in the laboratory can save a couple of hours in the library. -Frank H. Westheimer, chemistry professor (1912-2007) |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-22 : 01:45:51
|
The desired result wasShow material numbers with occurrence > 1 but with different revs. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|