×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Identify The number of occurrences of a given field

Identify The number of occurrences of a given field

Identify The number of occurrences of a given field

(OP)
Hello... I have the following data:

CODE

create table #temp (instrumentID varchar(25), saddition varchar(50), block varchar(10), Lot varchar(10), LotLength int)
insert into #temp values ('aa11', 'SP1', '5', '9', 1)
insert into #temp values ('aa11', 'SP1', '5', '10', 2)
insert into #temp values ('aa12', 'SP5', '9', '10', 2)
insert into #temp values ('aa12', 'SP5', '9', '11', 2)
insert into #temp values ('aa12', 'SP5', '9', '12', 2)
insert into #temp values ('aa12', 'SP6', '10', '5', 1)
insert into #temp values ('aa12', 'SP6', '10', '10', 2)
insert into #temp values ('aa13', 'SP7', '123', '31', 2)
insert into #temp values ('aa13', 'SP7', '123', '32', 2) 

I need to know each instrumentid, saddition, block where multiple lotlengths exist exit per each instrumentid, saddition, block.

In this example:
'aa11' has 2 separate lotlengths for 'aa11', 'sp1', '5'
'aa12' has 2 separate lotlengths for 'aa12', 'sp6', '10'

I'm hoping for a query that can show this. I just can't get my grouping right.

I tried:

CODE

select distinct instrumentid, saddition, block
from #temp
group by instrumentid, saddition, block
having count(block) > 1 

But this doesn't work.
Thanks!

RE: Identify The number of occurrences of a given field

I have found that the syntax for DISTINCT operates differently across various databases. Here is a trick that works on all databases - concatenating the fields.

select distinct(instrumentid + saddition + block)
from #temp
group by (instrumentid + saddition + block)
having count(instrumentid + saddition + block) > 1

If you need the individual columns, then add them to the query, make that query a subquery, and select the individual fields from the subquery.

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


RE: Identify The number of occurrences of a given field

(OP)
Brilliant! that worked like a charm

RE: Identify The number of occurrences of a given field

If it "worked like a charm", how about awarding John a Star...ponder
Click on Great Post! link on his reply.


---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close