Creating record to accept counter update
dbase: MS SQL 2005
I want to update a counter using SQL:
UPDATE mycountertable
SET mycounter = mycounter + 1
WHERE thecounter = 1234
If 'thecounter' with the value of 1234 exists in the dbase, then mycounter will update mycounter by 1, however if the record mycounter =1234 does not exist no update will take place
The question I have is do I have to check if thecounter=1234 exists first, then if not create it with an insert, or is anybody aware of a way for SQL to automatically create the record (in this case it would start with value 1) if the record does not exist, in one swoop, without having to go see if it exists first?
Thanks
Mark
