I have a stored procedure in SQL Server 2000 that basically deletes all the data from a table and inserts some new data into the same table. I call this procedure in powerbuilder 7 and I am passing 2 datetime variables and a string to the procedure (recieved as datetime and varchar(25).
For some reason my procedure isn't executeing. when I run the delete and the insert in query analyzer they work. I even tried a commit after the delete to see if the table gets emptied. Nothing happens. the procedure is below.
ALTER PROCEDURE [dbo].[msp_mpprode]
(@start datetime, @end datetime, @location varchar(25))
as
begin
truncate table mpprode
commit
Insert into [dbo].[mpprode](
part, machine, qty, downtime, pph, stdcrew, stdrun, actcrew, actrun)
SELECT audit_trail.part,
audit_trail.from_loc,
SUM(audit_trail.quantity),
(SELECT SUM(downtime.down_time) FROM downtime WHERE (downtime.trans_date BETWEEN @start AND @end) AND downtime.part = audit_trail.part),
part_machine.parts_per_hour,
part_machine.crew_size,
SUM(audit_trail.quantity)/part_machine.parts_per_hour,
0.0001,
0.0001
FROM {oj audit_trail LEFT OUTER JOIN part_machine ON audit_trail.part = part_machine.part AND audit_trail.from_loc = part_machine.machine}
WHERE audit_trail.date_stamp >= @start AND
audit_trail.date_stamp <= @end AND
audit_trail.type = 'J' AND
part_machine.machine IN (SELECT location.code FROM location WHERE location.group_no = @location)
GROUP BY audit_trail.part,
audit_trail.from_loc,
part_machine.parts_per_hour,
part_machine.crew_size
end
GO
For some reason my procedure isn't executeing. when I run the delete and the insert in query analyzer they work. I even tried a commit after the delete to see if the table gets emptied. Nothing happens. the procedure is below.
ALTER PROCEDURE [dbo].[msp_mpprode]
(@start datetime, @end datetime, @location varchar(25))
as
begin
truncate table mpprode
commit
Insert into [dbo].[mpprode](
part, machine, qty, downtime, pph, stdcrew, stdrun, actcrew, actrun)
SELECT audit_trail.part,
audit_trail.from_loc,
SUM(audit_trail.quantity),
(SELECT SUM(downtime.down_time) FROM downtime WHERE (downtime.trans_date BETWEEN @start AND @end) AND downtime.part = audit_trail.part),
part_machine.parts_per_hour,
part_machine.crew_size,
SUM(audit_trail.quantity)/part_machine.parts_per_hour,
0.0001,
0.0001
FROM {oj audit_trail LEFT OUTER JOIN part_machine ON audit_trail.part = part_machine.part AND audit_trail.from_loc = part_machine.machine}
WHERE audit_trail.date_stamp >= @start AND
audit_trail.date_stamp <= @end AND
audit_trail.type = 'J' AND
part_machine.machine IN (SELECT location.code FROM location WHERE location.group_no = @location)
GROUP BY audit_trail.part,
audit_trail.from_loc,
part_machine.parts_per_hour,
part_machine.crew_size
end
GO