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
 General SQL Server Forums
 New to SQL Server Programming
 get count for data change

Author  Topic 

bluemagic74
Starting Member

15 Posts

Posted - 2012-01-13 : 12:23:04
HI,

Table definition:

CREATE TABLE [dbo].[Table1](
[USERID] [int] NULL,
[MEDICATION_CODE] [tinyint] NOT NULL,
[DOSAGE_POINTS] [nvarchar](max) NOT NULL,
[PILLS_COUNT] [decimal](2, 1) NULL,
) ON [PRIMARY]

GO

Sample Data

USERID,MEDICATION_CODE,DOSAGE_POINTS,PILLS_COUNT
1111,16,10,1
1111,16,10,2
1111,43,5,2
1111,43,10,1
1111,43,20,1
1111,43,2.5,2
2222,15,2,1
2222,15,1,2
2222,10,1,2
2222,10,1,1
3333,15,2,1
3333,15,1,2

Now I need to write a script to pull ‘countdosagechange’ per user

For ex:

UserID, countdosagechange
1111,4

Thanks for your help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-13 : 12:50:01
do you've any unique valued column or audit column in your table?

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

Go to Top of Page

bluemagic74
Starting Member

15 Posts

Posted - 2012-01-15 : 11:55:03
USERID, MEDICATION_CODE are unique columns
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-15 : 13:21:47
nope. i can see they're repeating in above data. then how do you tell they're unique?

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

Go to Top of Page
   

- Advertisement -