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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 need urgent help to find out the count and pid

Author  Topic 

jenskp
Starting Member

5 Posts

Posted - 2010-11-03 : 00:45:56
Hello,
I have a table structure in this format

Username Count Pid
A1 4 0
C1 2 A1
C2 0 A1
C3 0 C1
C4 0 C1


When A1 is inserted, the count will be 0 and Pid will be 0.
But, when C1 is inserted, the Count of C1 will be 0 and A1 will be 1 and Pid will be A1.
When C2 is inserted, the Count of C2 will be 0 and A1 will be 2 and Pid will be A1
But, when C3 is inserted, the count of C1 will be 1 and C2, C3 and C4 will be 0 and A1 will be 3.
And the Pid’s of C3 and C4 will be C1 and so on..

So, how will I find out the Count and Pid’s C1.C2,…..CN?


- Thanks
Jenskp

KlausEngel
Yak Posting Veteran

85 Posts

Posted - 2010-11-05 : 21:41:21
Not sure I understand what you need but isn't it as simple as:
SELECT username, Pid, SUM(Count) as YourCount
FROM TableName
GROUP BY username, Pid
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-11-10 : 10:57:26
see

http://msdn.microsoft.com/en-us/library/ms186243.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -