您的查询对我不起作用;它包含一个错误。在您选择的“金额”之后添加一个逗号:
select
a.amount as Amount,
b.EmployeeName
from salesTable a
left outer join nameEmployees b on(b.id=a.employeeId)
where ItemId=@ItemId
顺便说一句,这是我的测试,效果很好。您可能还需要仔细检查表中的数据:
CREATE TABLE #salesTable ( ItemId int, amount money, employeeId int )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 100.00, 1 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 101.00, 1 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 102.00, 1 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 103.00, 1 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 104.00, 1 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 105.00, 2 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 106.00, 2 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 107.00, 2 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 108.00, 2 )
INSERT INTO #salesTable ( ItemId, amount, employeeId ) VALUES ( 1001, 109.00, 2 )
CREATE TABLE #nameEmployees ( id int, employeeName varchar(50) )
INSERT INTO #nameEmployees ( id, employeeName ) VALUES ( 1, 'John Smith' )
INSERT INTO #nameEmployees ( id, employeeName ) VALUES ( 2, 'Jane Doe' )
select
a.amount as Amount,
b.EmployeeName
from #salesTable a
left outer join #nameEmployees b on(b.id=a.employeeId)
where ItemId=1001