如果这是参数嗅探,请尝试添加
option(recompile)到查询的末尾。我建议创建一个存储过程,以更易于管理的方式封装逻辑。也同意-
根据示例判断,如果只需要三个参数,为什么要传递五个参数呢?您可以改用此查询吗?
select TrustAccountValue from( SELECt MAX (tal.trustaccountlogid), tal.TrustAccountValue FROM TrustAccountLog AS tal INNER JOIN TrustAccount ta ON ta.TrustAccountID = tal.TrustAccountID INNER JOIN Users usr ON usr.UserID = ta.UserID WHERe usr.UserID = 70402 AND ta.TrustAccountID = 117249 AND tal.TrustAccountLogDate < '3/1/2010 12:00:00 AM' group by tal.TrustAccountValue) q
而且,根据执行查询的用户的语言设置,使用的日期格式不明确,这是值得的。例如,对我来说,这是1月3日,而不是3月1日。看一下这个:
set language us_englishgoselect @@language --us_englishselect convert(datetime, '3/1/2010 12:00:00 AM')goset language britishgoselect @@language --britishselect convert(datetime, '3/1/2010 12:00:00 AM')
推荐的方法是使用“ ISO”格式yyyymmdd hh:mm:ss
select convert(datetime, '20100301 00:00:00') --midnight 00, noon 12



