Click here to Skip to main content
15,895,423 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
If any can help. I need code that check every time a company has being chosen for something the Referral column to add 1

so if company abc inc is chosen for labor insert the number 1
if company abc inc is chosen for electrical if referral is < 1 add 1 = 2 and so on.

Database Table Company
Columns:
coID
CompanyName nvarchar
Address nvarchar
City nvarchar
State nvarchar
Zip numeric
Services nvarchar
Referral numeric
Posted
Comments
shakil0304003 23-Jan-11 22:47pm    
Not clear!!!
postonoh 23-Jan-11 22:51pm    
Ok.. I have the code that when user check the box for referral it puts a number 1 in the database column referral. so when a user go to save it has to first check to see if check box is check then check the sql server database column referral if not empty add 1 to the existing number.

1 solution

There are a number of things that are wrong with this.

Your company table has event information in it, this should be removed to another table with a FK to the Company table.

ServicesTable
ServiceID
CompanyID
Service
Date Etc...

If you cannot change your data structure then look into row_number, running totals and partition, this assumes sql 2005 or greater
 
Share this answer
 
Comments
postonoh 23-Jan-11 23:05pm    
I can change the data structure. no problem. I just need an idea on the best way to do this. with sample code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900