0

I have an Excel spreadsheet with 2000 rows of data. I need to create a SQL script to insert the data into a table. Below is the formula I used in Excel and it works for creating the insert statement, but how do I "Not Insert" if DiagnosisCode already exists?

= "INSERT INTO CommonDiagnosis (DiagnosisCode, Description, ActiveThru, ActiveThruEnteredBy, DiagnosisFormat) VALUES('" & A3 & "', '" & B3 & "', '" & C3 & "', '" & D3 & "', '" & E3 & "')"
Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34
John Molina
  • 179
  • 3
  • 14

1 Answers1

0

You could try using an IF statement:

IF NOT EXISTS
 ( SELECT DiagnosisCode 
   FROM CommonDiagnosis
 )
BEGIN
INSERT INTO CommonDiagnosis (DiagnosisCode,Description,ActiveThru,ActiveThruEnteredBy,DiagnosisFormat)
VALUES ('"&A3&"','"&B3&"','"&C3&"','"&D3&"','"&E3&"')
END;
Hexana
  • 1,095
  • 2
  • 12
  • 35