我在SQL Server中有以下存储过程:
DECLARE @SQL_DtsAcumGPSDataZeros NVARCHAR(MAX);
SET @SQL_DtsAcumGPSDataZeros= N'SELECT [counter]
,[iID]
,[iVehicleID]
,[fTripDistance]
,[dtDateTime]
,[fLongitude]
,[fLatitude]
,[bLatLongValid]
,[fSpeed]
,[bIgnition]
,[bStopFlag]
,[fTripTime]
,[bWorkHours]
,[iLogReason]
,[bLatLongValidGuess]
,[bAux1]
,[bAux2]
,[bAux3]
,[bAux4]
,[bAux5]
,[bAux6]
,[bAux7]
,[bAux8]
INTO ' + @DtsAcumGPSDataZeros + N'
FROM ' + @DtsAcumGPSData +
N' WHERE fTripDistance= 0'
EXECUTE sp_executesql @SQL_DtsAcumGPSDataZeros
PRINT @SQL_DtsAcumGPSDataZeros
GO
并获得错误
Msg 102,Level 15,State 1,Line 2
'0'附近的语法不正确。
答案 0 :(得分:0)
尝试使用0作为参数
DECLARE @SQL_DtsAcumGPSDataZeros NVARCHAR(MAX),
@id int = 0
SET @SQL_DtsAcumGPSDataZeros= N'SELECT [counter]
,[iID]
,[iVehicleID]
,[fTripDistance]
,[dtDateTime]
,[fLongitude]
,[fLatitude]
,[bLatLongValid]
,[fSpeed]
,[bIgnition]
,[bStopFlag]
,[fTripTime]
,[bWorkHours]
,[iLogReason]
,[bLatLongValidGuess]
,[bAux1]
,[bAux2]
,[bAux3]
,[bAux4]
,[bAux5]
,[bAux6]
,[bAux7]
,[bAux8]
INTO ' + @DtsAcumGPSDataZeros + N'
FROM ' + @DtsAcumGPSData +
N' WHERE id = @id'
EXEC sp_executesql @SQL_DtsAcumGPSDataZeros, N'@id nvarchar(100)', @id
PRINT @SQL_DtsAcumGPSDataZeros