Question: I have a table that keeps track of IP addresses with 3 fields -- ID, IP, TOTAL.

If I'm inserting a duplicate IP value, I'd like to just increment the TOTAL field by 1.

How should I do this?

Answer: 
You can use a query like this if your IP is UNIQUE

```
INSERT INTO tablename (id, ip, total) VALUES (1, xxx.xxx.x.x, 1)
ON DUPLICATE KEY UPDATE total = total+1;

```
You mean counting the total ? then add 1 if `IP` is already existing ?

```
    DECLARE @Total INT = (SELECT COUNT(Total) From TableName)

    IF EXIST (SELECT IP From TableName)
       BEGIN
          SET @Total = @Total + 1
       END

    INSERT INTO...

```