October 17, 2011 at 1:51 pm
This is what is in my table
EmpidName EmergContact
123Smith, JimSmith, Judy
123Smith, JimSmith, John
596Doe, JaneDoe, John
596Doe, JaneDoe, Chris
There is no number field for EmergContact. How do I get it as:
EmpidName EmergContactNumber
123Smith, JimSmith, Judy1
123Smith, JimSmith, John2
596Doe, JaneDoe, John1
596Doe, JaneDoe, Chris2
I've tried Count(), Count(Distinct Empid), @@RowCount but nothing works.
Any help would be much appreciated.
October 17, 2011 at 1:59 pm
Have a look at the Row_Number() windowed function.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
October 17, 2011 at 2:00 pm
Looks a lot like homework, so I'll offere a hint to help you get along.
you need to use GROUP BY employee along with a count(); i think that will get you were you want to be;
that will get you the count, sorry; the row_number() suggestion will get you the arbitrary counter per employee, as suggested.
Lowell
October 17, 2011 at 2:36 pm
SELECT Empid, Name, EmergContact,
ROW_NUMBER() OVER (PARTITION BY Empid order BY Name) [Number]
FROM table
October 17, 2011 at 2:43 pm
Steve Cullen (10/17/2011)
SELECT Empid, Name, EmergContact,
ROW_NUMBER() OVER (PARTITION BY Empid order BY Name) [Number]
FROM table
Yup - that should pretty much do it.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
October 17, 2011 at 2:53 pm
That did it. It's always the trivial things that stump me...
Thanks guys.
October 17, 2011 at 2:56 pm
You're welcome.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply