Wow, I appreciate the post. I do have a couple of questions for you. I have never use variables before in SQL but I can see that power in doing so. What is the difference between the functionality between
INSERT INTO years (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, [dec])
VALUES (@JanNew, @FebNew, @MarNew, @AprNew, @MayNew, @JunNew, @JulNew, @AugNew, @SepNew, @OctNew, @NovNew, @DecNew)
AND
INSERT INTO years (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, [dec])
VALUES (0,0,0,0,0,0,0,0,0,0,0,0)
If I understand this correctly, it looks like you are passing variables into the procedure...
CREATE PROCEDURE insert_new_pers_wr_records
@act int, @wr int, @pid int, @JanNew real, @FebNew real, @MarNew real, @AprNew real, @MayNew real, @JunNew real, @JulNew real, @AugNew real, @SepNew real, @OctNew real, @NovNew real, @DecNew real
then inserting those variables into the years table...
INSERT INTO years (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, [dec])
VALUES (@JanNew, @FebNew, @MarNew, @AprNew, @MayNew, @JunNew, @JulNew, @AugNew, @SepNew, @OctNew, @NovNew, @DecNew)
grabbing the identity from the years table...
Set @planID = @@Identity
(This is where I don't quite understand what is going on)
INSERT INTO years (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, [dec])
VALUES (0,0,0,0,0,0,0,0,0,0,0,0)
Then you insert the identity values into the child table...
INSERT INTO personmonths (id_activitycodes, id_years_planned, id_years_actual, id_workrequests, id_personnel, [timestamp])
VALUES (@act, @planID, @actID, @wr, @pid, 123456789)
Is this correct? Right now my inserts look something like this
INSERT INTO PLATE (LICENSE_SEQ_NUMBER,PLATE_NUMBER, PLATE_STATE)
SELECT DISTINCT XML_VEHICLE_SUMMARY.LICENSE_SEQ_NUMBER,
XML_VEHICLE_SUMMARY.LICENSE_PLATE_NUMBER,
XML_VEHICLE_SUMMARY.LICENSE_PLATE_STATE
FROM XML_VEHICLE_SUMMARY
WHERE XML_VEHICLE_SUMMARY.LICENSE_SEQ_NUMBER != NULL
This would represent the child table insert and LICENSE_SEQ_NUMBER is the identity key that I would have to grab from the previous insert statement. How do I get the values from the XML... table to the PLATE table by using variables as you have shown?