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
 Database Design and Application Architecture
 HowTo Buisness Rule: MultiRows total=Constant

Author  Topic 

Angel0in
Starting Member

4 Posts

Posted - 2009-02-23 : 16:23:46
Hello to all helpers,

I have a table in database:

Create table TestTable (GroupId int, ANumber int)

with samle data :

GroupId ANumber
-------------------
1 10
1 70
1 20
2 60
2 40
3 35
3 40
3 15
3 10


My Buisness Rule requirement is : Keep Group Total to 100

like for

Group 1 >> 10+70+20=100
Group 2 >> 60+40=100
Group 3 >> 35+40+15+10=100

Is it possible to use some constraint ( but it is single row level) ?

How to implement this buisness rule on SQLServer ?

Thanks

mfemenel
Professor Frink

1421 Posts

Posted - 2009-02-23 : 16:27:56
Sounds like a good candidate for a check constraint or a trigger.

Mike
"oh, that monkey is going to pay"
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-23 : 16:44:58
You can use scalar function to calculate sum and use it in check constraint.
Go to Top of Page

Angel0in
Starting Member

4 Posts

Posted - 2009-02-24 : 11:51:12
Thanks mfemenel and sodeep
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-24 : 12:19:52
Welcome
Go to Top of Page
   

- Advertisement -