SQL Server 2005通过C#(VS 20015)。知道为什么WHERE
不起作用?
SQL语句是:
SELECT
AA003Employee.idEmployee,
AA001Person.LastName, AA001Person.FirstName,
AA017JobTitle.JobTitle, AA017JobTitle.Department,
AA003Employee.Disabled
FROM
AA003Employee
JOIN
AA001Person ON AA003Employee.idPerson = AA001Person.idPerson
JOIN
AA017JobTitle ON AA003Employee.idJobTitle = AA017JobTitle.idJobTitle
ORDER BY
AA001Person.LastName ASC, AA001Person.FirstName ASC,
AA017JobTitle.JobTitle ASC
WHERE
AA003Employee.Disabled = 'N';
尝试:
答案 0 :(得分:6)
您的问题是WHERE
子句的放置。 SQL关心语句中子句的顺序。但是你也应该学会使用表别名:
SELECT e.idEmployee, p.LastName, p.FirstName, jt.JobTitle, jt.Department, e.Disabled
FROM AA003Employee e JOIN
AA001Person p
ON e.idPerson = p.idPerson JOIN
AA017JobTitle jt
ON e.idJobTitle = jt.idJobTitle
WHERE e.Disabled = 'N'
ORDER BY p.LastName ASC, p.FirstName ASC, jt.JobTitle ASC;
请参阅?查询更容易编写和阅读。
答案 1 :(得分:1)
用,
替换查询SELECT AA003Employee.idEmployee, AA001Person.LastName, AA001Person.FirstName, AA017JobTitle.JobTitle, AA017JobTitle.Department, AA003Employee.Disabled
FROM AA003Employee
JOIN AA001Person ON AA003Employee.idPerson=AA001Person.idPerson
JOIN AA017JobTitle ON AA003Employee.idJobTitle=AA017JobTitle.idJobTitle
WHERE AA003Employee.Disabled = 'N'
ORDER BY AA001Person.LastName ASC, AA001Person.FirstName ASC, AA017JobTitle.JobTitle ASC
答案 2 :(得分:0)
用以下SQL语句替换查询
SELECT
AA003Employee.idEmployee,
AA001Person.LastName,
AA001Person.FirstName,
AA017JobTitle.JobTitle,
AA017JobTitle.Department,
AA003Employee.Disabled
FROM AA003Employee
JOIN AA001Person ON AA003Employee.idPerson=AA001Person.idPerson
JOIN AA017JobTitle ON AA003Employee.idJobTitle=AA017JobTitle.idJobTitle
WHERE AA003Employee.Disabled = 'N';
ORDER BY AA001Person.LastName ASC, AA001Person.FirstName ASC, AA017JobTitle.JobTitle ASC