SELECT AttestInvoice.verNo, AttestInvoice.invoiceCompany, AttestInvoice.storeID, AttestInvoice.invoiceSum, AttestInvoice.invoiceID, AttestAccountInfo.completedDate
FROM AttestInvoice INNER JOIN
AttestAccountInfo ON AttestInvoice.invoiceID = AttestAccountInfo.invoiceID
WHERE (AttestInvoice.storeID > 0) AND (AttestInvoice.storeID IN
(SELECT storeID
FROM EmployeesStoresByUser
WHERE (userName = @userName))) AND (AttestAccountInfo.approved = 1)
OR (AttestInvoice.storeID > 0) AND (AttestInvoice.storeID IN
(SELECT storeID
FROM EmployeesStoresByUser
WHERE (userName = @userName))) AND (AttestAccountInfo.denied = 1)
ORDER BY AttestAccountInfo.completedDate DESC
SELECT i.verNo,
i.invoiceCompany,
i.storeID,
i.invoiceSum,
i.invoiceID,
a.completedDate
FROM AttestInvoice i
INNER JOIN AttestAccountInfo a ON i.invoiceID = a.invoiceID
INNER JOIN EmployeesStoresByUser e ON i.StoreID = e.StoreID
WHERE a.storeID > 0
AND e.userName = @userName
AND (a.approved = 1 OR a.denied = 1)
ORDER BY aai.completedDate DESC
SELECT i.verNo,
i.invoiceCompany,
i.storeID,
i.invoiceSum,
i.invoiceID,
a.completedDate
FROM AttestInvoice i
INNER JOIN AttestAccountInfo a ON i.invoiceID = a.invoiceID
INNER JOIN EmployeesStoresByUser e ON i.StoreID = e.StoreID
WHERE a.storeID > 0
AND e.userName = @userName
AND (a.approved = 1 OR a.denied = 1)
ORDER BY
a.completedDate DESC
ASKER
SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.
TRUSTED BY
Why aren't you including EmployeesStoresByUser in the main query ?