【发布时间】:2018-03-06 20:27:12
【问题描述】:
在我的存储过程中,我有以下语句:
SELECT TOP 200
C.CustomerNumber,
C.CustomerName,
C.AccountManager,
C.CustomerId
FROM
Customer C WITH(NOLOCK, index (UQ_Customer_CustomerNumber))
LEFT JOIN
CustomerQuotingPreference cp WITH(NOLOCK) ON cp.CustomerId = C.CustomerId
WHERE
(C.CustomerName LIKE ('%' + @searchString + '%')
OR C.CustomerNumber LIKE ('%' + CONVERT(VARCHAR(61), @searchString) + '%')))
ORDER BY
C.CustomerName
我现在想检查一下,如果此选择没有返回任何记录,请运行不同的选择。
【问题讨论】:
-
看看
@@ROWCOUNTdocs.microsoft.com/en-us/sql/t-sql/functions/… -
设置Bad Habits to kick - putting NOLOCK everywhere - 不建议在任何地方都使用它 - 恰恰相反!
-
通常我将这种逻辑放在应用程序代码中。
-
NOLOCK 在某些边缘情况下有意义......但我怀疑这是其中之一,尤其是如果你想要干净的数据!
标签: sql sql-server-2008 stored-procedures