欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

SQLServer拼接语句使用between and 出错,求助

程序员文章站 2024-02-12 15:25:52
...

最后答案: ALTER procedure [dbo].[GetBy_ItemName_BetweenTime] @itemName nvarchar(50), @beginTime datetime, @endTime datetime as declare @tableName nvarchar(50) set @tableName = (select TableName from TQueryItem where ItemName=@itemName) ex

最后答案:

ALTER procedure [dbo].[GetBy_ItemName_BetweenTime]
@itemName nvarchar(50),
@beginTime datetime,
@endTime datetime
as

declare @tableName nvarchar(50)
set @tableName = (select TableName from TQueryItem where ItemName=@itemName)

exec ('select * from '+@tableName+' where YYMMDD between '''+@beginTime+''' and '''+@endTime+'''')

时间上的单引号问题。。。我蠢了