Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Use a cursor to insert unique field into table

$
0
0

I have never used a cursor before so I am new to this. I'm wondering if someone could point me in the right direction.

I have a table in my database that already contains some data. There are only 5 fields in the table. I am going to need to take data from a view and insert it into the table via a stored procedure. Only thing is, I need to figure out a way to not duplicate one of the fields (I'll call it Field 1) - so if the row I am trying to insert has a Field 1 value that is already in the table I do not insert that specific row. Distinct won't work in this case because the other field values in that row might be different. I don't know if this makes a difference - but I am using the same stored procedure that I used to insert the information that is already in the table.

Is anybody able to help with this? Some sample code would be extremely helpful. Thanks!


Viewing all articles
Browse latest Browse all 7129

Trending Articles