Need help on sqlquery instead of cursor

  • I have two tables (label,product) and columns are as follows,

    Product:

    p_id (int)(identity),name(nvarchar(100),uniquecode(nvarchar(100)),description(nvarchar(1000)

    label:

    l_id(int)(Identity),name(nvarchar(100),uniquecode(nvarchar(100),p_id(int),description nvarchar(1000)

    My requirement is i have to compare label with product based on uniquecode and if data doesn't exits in prodcut than take data from label and insert into product and get the p_id and update into label table based on uniquecode.

    Currently i am done with the help of fast forward cursor to loop through records from label and insert into product, get the p_id and update into label table(p_id column). Is there any better way to avoid cursor by writing this logic using sql query to improve the performance.

    also can it be done using Merge statement? If yer please give me sample query

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply