0
當我運行這段代碼它給我的錯誤,我沒有什麼不對的錯誤轉換數據類型爲varchar爲bigint SQL錯誤
DECLARE @COUNTER BIGINT
DECLARE @SQL varchar (800)
DECLARE @SQL2 nvarchar(max) = N'SELECT @Counter = MIN(CAST('[email protected]+' AS BIGINT)) FROM '[email protected]+' WHERE dbo.IsInteger('[email protected]+') = 1 and '[email protected]+' >=''' [email protected]+''' and '[email protected]+' <= '''[email protected]+''''
PRINT @SQL2
-- EXEC @SQL
EXEC sp_executesql @SQL2, N'@Counter BIGINT OUTPUT', @Counter = @Counter OUTPUT
PRINT @Counter
你的問題提到不清楚。你是否聲明@fieldand是什麼類型的? –
'@ cfield'是否包含一些無法轉換爲'bigint'的值?另外,當使用'PRINT @ SQL2'打印時,查詢的效果如何? – jpw
@cfield is varchar ... and ddatefrm and ddateto is varchar –