I get the following error when I run the following stored procedure: 'ODBC Error Code = 22008 (Datetime field overflow)
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting datetime from character string.' It will be a miracle if I get this working, it is driving me crazy. Thanks in anticipation of any help.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE sp_GetDaybook
@sContactIDList varchar (1000),
@sStock varchar (20),
@dtFrom datetime,
@dtTo datetime
AS
DECLARE @MySQL varchar (500)
DECLARE @MyWhere varchar (1200)
DECLARE @MyOrder varchar (100)
SET @MySQL = '
SELECT sDaybookID, sClientID, iContactID, dtComment, sStock, sAuthor, sComment
FROM Daybook'
SET @MyWhere = '
WHERE 0 = 0'
IF @sContactIDList IS NOT NULL SET @MyWhere = @MyWhere + 'AND iContactID IN' + '(' + @sContactIDList + ')'
IF @sStock IS NOT NULL SET @MyWhere = @MyWhere + 'AND sStock LIKE' + '''' + '%' + @sStock + '%' + ''''
SET @MyWhere = @MyWhere + 'AND dtComment BETWEEN' + @dtFrom + 'AND'+ @dtTo
SET @MyOrder = '
ORDER BY dtComment Asc'
EXEC (@MySQL + @MyWhere + @MyOrder)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
2004-02-08 01:52:00
if you are passing dates using a string.