I have a stored procedure that receives a TVP as input. Now, I need to check the received data for a particular ID in a primary key column. If it exists, then I just need to update the table using those new values for other column (sent via TVP). Else, do an insert.
How to do it?
CREATE PROCEDURE ABC
@tvp MyTable READONLY
AS
IF EXISTS (SELECT 1 FROM MYTAB WHERE ID= @tvp.ID)
DO update
ELSE
Create
Just wondering the if exists
loop I did is correct. I reckon its wrong as it will only check for first value and then update. What about other values? How should I loop through this?