SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help - Pivot table


Help - Pivot table

Author
Message
m.mukesh.mca2009
m.mukesh.mca2009
SSC-Enthusiastic
SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)

Group: General Forum Members
Points: 104 Visits: 68
Hi

I have a table like below.
ID eID inCount outCount
41772 0 NULL NULL
10000 1033 1 7
10000 1034 6 1
10000 1035 NULL 1
10000 1036 1 NULL
10000 1036 2 NULL
10000 1036 1 1

I want to table output like below

ID 1033COUNT 1033COUNT 1034COUNT 1034COUNT
41772 1 7 6 1
10000 1 7 6 1
10000 1 7 6 1

Please help. Thanks
Phil Parkin
Phil Parkin
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19526 Visits: 20462
m.mukesh.mca2009 (8/7/2014)
Hi

I have a table like below.
ID eID inCount outCount
41772 0 NULL NULL
10000 1033 1 7
10000 1034 6 1
10000 1035 NULL 1
10000 1036 1 NULL
10000 1036 2 NULL
10000 1036 1 1

I want to table output like below

ID 1033COUNT 1033COUNT 1034COUNT 1034COUNT
41772 1 7 6 1
10000 1 7 6 1
10000 1 7 6 1

Please help. Thanks


You have duplicate rows and duplicate columns in your sample output. Can you explain why? Or correct it to match what you really want.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
LutzM
LutzM
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10735 Visits: 13559
Also, please verify that your expected output is based on your sample data. I'd expect the current version doesn't.



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
TheSQLGuru
TheSQLGuru
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13129 Visits: 8566
While you are figuring out what you really want (and scripting sample tables/data for us to help you better), search the web for sql server CASE pivot and see if you can do it yourself

Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
m.mukesh.mca2009
m.mukesh.mca2009
SSC-Enthusiastic
SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)SSC-Enthusiastic (104 reputation)

Group: General Forum Members
Points: 104 Visits: 68
Hi, eID have only unique values but ID may have duplicate values
Phil Parkin
Phil Parkin
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19526 Visits: 20462
m.mukesh.mca2009 (8/7/2014)
Hi, eID have only unique values but ID may have duplicate values


By being lazy and not providing what people are asking for, you are making this thread more painful than it needs to be.

If you will not take the time to provide accurate sample data and desired output which matches the sample data, why should the unpaid volunteers here take the time to help you out?


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
LutzM
LutzM
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10735 Visits: 13559
m.mukesh.mca2009 (8/7/2014)
Hi, eID have only unique values but ID may have duplicate values

That doesn't match the sample data you provided.
ID eID inCount outCount
41772 0 NULL NULL
10000 1033 1 7
10000 1034 6 1
10000 1035 NULL 1
10000 1036 1 NULL
10000 1036 2 NULL
10000 1036 1 1

Seems like you're not really interested to get the issue resolved. I'm out.



Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search