1
我一直在研究这个查询将近两天。下面有一张工作人员桌子。每个地点都有多位员工根据列出的alpha来获取他们需要照顾的客户名单。然而,阿尔法不是标准的单字符或双字符,而是他们将单个直到三个字母放在桌子上。我试图根据客户姓氏在这些alpha范围内获得客户名单和他们的分配人员,我尝试了很多查询,并且他们都在某个级别上失败。基于多个字符alpha的SQL Server 2008名称列表
我用一对夫妇的热膨胀系数,以获得订单的一切,试图在马克斯
declare @maxChar varchar(3) = (select min(len(val)) from (
select staffStartChar val from StaffAlphaList where staffLocId = 1
union
select staffEndChar from StaffAlphaList where staffLocId = 1
)temp)
select customerName
, upper(LTRIM(RTRIM(
LTRIM(RTRIM(ISNULL(employee.f_name, ''))) + ' ' +
LTRIM(RTRIM(ISNULL(employee.m_name, ''))) + ' ' +
LTRIM(ISNULL(employee.l_name, ''))
)))
from Customers with (nolock)
left outer join StaffAlphaList with (nolock)
on StaffAlphaList.staffLocId= Customers.LocId
left outer join employee with (nolock)
on employee.empl_no = StaffAlphaList.staffId
where lower(left(customerLastName, @maxChar)) between StaffAlphaList.staffStartChar and StaffAlphaList.staffEndChar
设置[坏习惯踢 - 把NOLOCK无处不在](http://blogs.sqlsentry.com/aaronbertrand/bad-habits-nolock-everywhere/) - 它是*不推荐*到处使用 - 相当相反! –