sql - Insert Table parameter to 2 different tables within a stored procedure -
i have table-valued parameter @supplierdata in stored procedure has columns follows
sname | slocation | curryearexpt | curryearimpt | prevyearexpt | prevyearimpt ---------- xxx | usa | 1000 | 2000 | 1000 | 2050 yyy | u.k | 8000 | 12000 | 10000 | 29000 the table needs inserted below 2 tables
supplier table:
sid | sname | slocation | (identity) | | | ---------- 1 | xxx | usa | 2 | yyy | u.k | and
supplierrecord table:
yearid | sid | curryearexpt | curryearimpt | prevyearexpt | prevyearimpt| ---------- 1 | 1 | 1000 | 2000 | 1000 | 2050 | 2 | 2 | 8000 | 12000 | 10000 | 29000 | where in 2nd table having reference sid created part of same stored procedure execution.
should insert record record @supplierdata parameter?
you use dense_rank function (https://msdn.microsoft.com/en-us/library/ms173825.aspx) on specify order , partitioning criteria. you'll numeric ids suppliers. insert them table parameter first , use 2 inserts
Comments
Post a Comment