[MS SQL] SQL 效能改善 - 不要在where用function

捞很久居然是因为在变数里用funtion

select *from CUST t2 with (nolock) and BirthDate between dbo.YYYYMMDDtoCYMMDD (convert(varchar, getdate(), 112))-5 and dbo.YYYYMMDDtoCYMMDD (convert(varchar, getdate(), 112))

#这样就解决了

declare @msDate int declare @meDate int set @msDate = dbo.YYYYMMDDtoCYMMDD (convert(varchar, getdate(), 112))-5set @meDate = dbo.YYYYMMDDtoCYMMDD (convert(varchar, getdate(), 112))select * from CUST t2 with (nolock) where BirthDate between  @msDate and  @meDate 

如果上面的方式还是不行,可以再试试用
EXEC('select ....')


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章