N
N
Nexta2019-02-04 04:48:14
Transact SQL
Nexta, 2019-02-04 04:48:14

How to validate Insert data before inserting into cursor?

The question is this:
Data is selected from tables and added to cursor variables:

INSERT into [Myserver\my_instance].Special_table.dbo.stat (my_col1,my_col2,my_col3,my_col4,my_col5,my_col6,my_col7) VALUES (@var1, @var2,  @var3, @var4, @var5, @var6, @var7);

it is necessary to check my_col1 + my_col2 so that this pair does not give matches when inserted from the cursor.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2019-02-04
@Nexta

EXISTS .

IF NOT EXISTS (SELECT * FROM [Myserver\my_instance].Special_table.dbo.stat WHERE ([my_col1] = @var1) AND ([my_col2] = @var2))

D
d-stream, 2019-02-04
@d-stream

And what should happen if there is a match?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question