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.
| Author |
Topic |
|
pha2er
Starting Member
6 Posts |
Posted - 2002-05-23 : 05:28:22
|
| Hi there,I have a table which holds details of people other people have referred (a refer a friend thing!).Just now, it adds everyone that is referred, regardless of whether of not they're in the table already.What I'm now trying to do is check to see if this person has already been referred, and incrementing a field called 'strikes' by 1, so I know how many times a person is being referred.If that email is not in the table already, I need to add it and set 'strikes' to 1.The last bit I can do np, but I'm stumped about the first bit!Anyone help?thanks! |
|
|
makimark
Starting Member
34 Posts |
Posted - 2002-05-23 : 05:51:41
|
quote: Hi there,I have a table which holds details of people other people have referred (a refer a friend thing!).Just now, it adds everyone that is referred, regardless of whether of not they're in the table already.What I'm now trying to do is check to see if this person has already been referred, and incrementing a field called 'strikes' by 1, so I know how many times a person is being referred.If that email is not in the table already, I need to add it and set 'strikes' to 1.The last bit I can do np, but I'm stumped about the first bit!Anyone help?thanks!
HiWhat are you using ? ASP VB or something ? First check if the email exists, if yes increment the strikes like thisstrikes = strikes + 1Mark |
 |
|
|
pha2er
Starting Member
6 Posts |
Posted - 2002-05-23 : 07:14:07
|
| is there no way to do it with a SQL Query? |
 |
|
|
YellowBug
Aged Yak Warrior
616 Posts |
Posted - 2002-05-23 : 07:16:41
|
| You can try something like this:DECLARE @email varchar(80)IF NOT EXISTS ( SELECT email_in FROM tblRefer WHERE email = @email)BEGIN -- Insert new row INSERT INTO tblRefer (email) VALUES (@email)ENDELSEBEGIN UPDATE tblRefer SET strike = strike + 1 WHERE email = @emailENDEdited by - YellowBug on 05/23/2002 07:18:46 |
 |
|
|
pha2er
Starting Member
6 Posts |
Posted - 2002-05-23 : 07:22:44
|
| thanks, I'll give it a go! |
 |
|
|
|
|
|
|
|