Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using deterministic sql inserts

Status
Not open for further replies.
Jun 9, 2006
159
US
Hello,

I'd like to run a check on a table before I insert a new row. I want to check if the IP Address in this table exists before the insert:

INSERT INTO views VALUES (@IpAddress, @VideoId)

Would I just run a select for the ipaddress and then count the result set rows?

Thanks,

Shawn Molloy
Seattle, WA
 
Code:
If Exists(Select * From TableName Where IpAddress = @IpAddress)
  Begin
    -- Record exists, update the record???
  End
Else
  Begin
    -- Insert the record
    INSERT INTO views VALUES (@IpAddress, @VideoId)
  End

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top