I implement a software application that uses a SQL server database. I'm running a stored proc in a macro I created in my application, however, I cannot get the "StartTime" (datetime field) to update. Here is the code:
ALTER PROCEDURE [dbo].[pAfterFirstRun] ( @scheduleDate datetime ) AS
BEGIN
SET NOCOUNT ON;
CREATE TABLE #VehicleId ( VehicleId INT )
INSERT INTO #VehicleId
(VehicleId)
SELECT VehicleId
FROM ResourceDaily
WHERE WorkDay = @scheduleDate
AND ResourceName = 'RUN 1'
AND ResourceCode IN (SELECT ResourceCode
FROM ResourceDailySchedule
WHERE WorkDay = @scheduleDate)
UPDATE ResourceDaily
SET StartTime = '1899-12-30 07:20:00.000'
WHERE WorkDay = @scheduleDate
AND ResourceName = 'RUN 2'
AND VehicleId IN (SELECT VehicleId
FROM #VehicleId)
UPDATE ResourceDaily
SET StartAddress = '568 BUCKS HILL RD',
StartCity = 'WATERBURY',
StartState = 'CT',
StartZipCode = '06704',
StartXCoord = '-73.029938',
StartYCoord = '41.606228'
WHERE WorkDay = @scheduleDate
AND ResourceName = 'RUN 2'
AND VehicleId IN (SELECT VehicleId
FROM #VehicleId)
END
I know this is a strange way to accomplish the job; originally, I didn't create a temp table. It was all done through one update statement and I kept changing it to see if I can get it to work.
The original update statement included the updates to StartTime, StartAddress, StartCity, StartState, StartXCoord and StartYCoord all in one statement and everything would update except the StartTime field.
I should also mention that if I were to run the UPDATE statement in Management Studio and set the @scheduleDate to '5/2/2011', the update statement will run correctly... it just doesn't seem to run in the application with the @scheduleDate parameter.