Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
adlo
Posting Yak Master
108 Posts |
Posted - 2005-02-15 : 03:54:24
|
| I have a table ScheduleFields are:Definition_ID intSchedule int,Item_ID int,OrderNo intOther fieldsI use negative values in Definition_ID to store template datae.g. Template for Definition 1 (Schedule is of no value because it's a template) Select * from Schedule WHERE Definition_ID=-1-1,0,1,1 ...-1,0,2,2 ...-1,0,3,3 ...Now I need to poplulate the same table for a spesific Schedule based on the Definition Template. Let's say Schedule 1 using template Definition 1.Thus I need multiple insert to achieve the follwing result1,1,1,1 ...1,1,2,2 ...1,1,3,3 ...I need to insert the (Select * from Schedule WHERE Definition_ID=-(given parameter Definition_ID)).The new Definition_ID must change to 1 (given parameter Definition_ID) and the Schedule must change to 1 (given parameter Schedule)I'm a bit lost can one do this in one stored proc?I can do the above using Insert ScheduleSelect 1, 1, Item_ID, OrderNo, ....from ScheduleWHERE Definition_ID=-1Now the tricky part is, if there is already entries for that spesific schedule item then OrderNo must be automatically incremented from where the previous OrderNo stopped for that spesific schedule.Is it still possible to do this in one stored proc? |
|
|
|
|
|
|
|