I have a T-SQL query in a stored procedure which inserts data into a table using SELECT command from another table. Problem is it stops query execution if it found duplicate entry in select table clause while inserting it in another table (I have imposed primarky key constraint on this)
I want SQL to skip the error occurred (i.e. don't throw it nd stop.. continue your execution) and go with next line of row inserting..
I know there are ways with TRANSACTION COMMIT ROLLBACK TRY CATCH but how to use them ?
My T-SQL :
Begin
Set @SQL='Insert Into AxisReports
Select *
From ReportData L
Left Join ATM A On L.ATMID=A.ATM
Where L.ATMID=A.ATM AND L.IssuerNetwork < > ''0000'' '
Exec(@SQL)
End
The source table may contain more than 5 Lac entries with very small no. of duplicate rows.
SELECTitself?SELECTto not bring back duplicates then. This will also allow you to select which duplicate row to use. As you haven't told us the table structures or the key columns for the unique index I can't give you any code though.