0

I need to insert the records that aren't existing in the table companies.

I'm using the @@ROWCOUNT method to check if it exists.

UPDATE companies SET `name`='<string>' WHERE `name`='<string>';
IF @@ROWCOUNT = 0
  INSERT INTO companies(`name`, temp) VALUES('<string>', 1);

This is what I do ^
And just keeping this error: Unknown system variable 'ROWCOUNT'

Panup Pong
  • 1,871
  • 2
  • 22
  • 44
MrLine
  • 638
  • 7
  • 25
  • 1
    `@@ROWCOUNT` is SQL Server syntax. Looks like you are using MySQL. https://chartio.com/resources/tutorials/how-to-insert-if-row-does-not-exist-upsert-in-mysql/ – Martin Smith Dec 14 '17 at 08:18
  • 1
    The code shown is not valid (standard) "SQL" - which DBMS are you using? –  Dec 14 '17 at 08:22
  • @MartinSmith thanks. Stupid, I didn't thought about the `ON DUPLICATE`. Can you set is as answer, so I can resolve this question ^^ – MrLine Dec 14 '17 at 08:23

0 Answers0