Hi,
I'm new to MS SQL and I'm trying to retrieve data from a certain table. I've wrote a SP but I always get a converting datetime from character string error. I don't now how I can fix the problem.
USE EDOC
/* Via deze Stored Procedure gaat men de Status gaan aanpassen van toestand Passief naar Open voor alle workflowtabellen.
Indien de geplande afhandelingsdatum binnen een bepaalde tijdspanne ligt wordt de Status van toestand verandert.
*/
GO
/* Nakijken of de Stored Procedure al bestaat.
Is dit het geval dan wordt deze eerst verwijderd om opnieuw aangemaakt te worden.
*/
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'usp_UpdateWorkflowStatus' AND type = 'P')
DROP PROCEDURE usp_UpdateWorkflowStatus
GO
CREATE PROCEDURE usp_UpdateWorkflowStatus
@tabelNaam nvarchar(150) -- variabele tabelnaam die gebruikt wordt in het SQL Update statement
AS
DECLARE @Query varchar(255)
SET @Query = 'UPDATE ' + RTRIM(@tabelNaam) + ' SET STATUS = 1 WHERE ((Status = 3)'
IF (@tabelnaam <> 'tblCPA' AND @tabelNaam <> 'tblAudit')
BEGIN
SET @Query = @Query + ' AND (GeplAfhDatum < ' + GetDate() + '))'
EXEC (@Query)
END
ELSE
BEGIN
SET @Query = @Query + ' AND (GeplAfhDatum < ' + DateAdd("d", 90, GetDate())+ '))'
EXEC (@Query)
END
Live fast, die young and leave a beautiful corpse behind.
I'm new to MS SQL and I'm trying to retrieve data from a certain table. I've wrote a SP but I always get a converting datetime from character string error. I don't now how I can fix the problem.
USE EDOC
/* Via deze Stored Procedure gaat men de Status gaan aanpassen van toestand Passief naar Open voor alle workflowtabellen.
Indien de geplande afhandelingsdatum binnen een bepaalde tijdspanne ligt wordt de Status van toestand verandert.
*/
GO
/* Nakijken of de Stored Procedure al bestaat.
Is dit het geval dan wordt deze eerst verwijderd om opnieuw aangemaakt te worden.
*/
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'usp_UpdateWorkflowStatus' AND type = 'P')
DROP PROCEDURE usp_UpdateWorkflowStatus
GO
CREATE PROCEDURE usp_UpdateWorkflowStatus
@tabelNaam nvarchar(150) -- variabele tabelnaam die gebruikt wordt in het SQL Update statement
AS
DECLARE @Query varchar(255)
SET @Query = 'UPDATE ' + RTRIM(@tabelNaam) + ' SET STATUS = 1 WHERE ((Status = 3)'
IF (@tabelnaam <> 'tblCPA' AND @tabelNaam <> 'tblAudit')
BEGIN
SET @Query = @Query + ' AND (GeplAfhDatum < ' + GetDate() + '))'
EXEC (@Query)
END
ELSE
BEGIN
SET @Query = @Query + ' AND (GeplAfhDatum < ' + DateAdd("d", 90, GetDate())+ '))'
EXEC (@Query)
END
Live fast, die young and leave a beautiful corpse behind.