Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Functional Difference Between 2 Queries

Author  Topic 

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2002-12-17 : 12:50:37
Hiya!
I may be very dim here, but can s/o point if there is functional difference between these two queries; i.e. they should return different results. I am aware that the execution plans and the query designs are different, and I am wondering about the results only.

Query 1:
SELECT P.*, (SELECT MAX(ServiceDate) FROM VouchersDetail WHERE Voucher = V.VoucherNo) AS ServiceDate, V.*, S.*, S.Insco AS
SubmitInsCo FROM (SELECT VoucherNo, MAX(SubmitDate) AS SubmitDate FROM Submissions GROUP BY VoucherNo)SD INNER JOIN Vouchers V ON V.Voucherno
= SD.VoucherNo INNER JOIN Patients P ON P.ID = V.PatID INNER JOIN Submissions S ON V.VoucherNo = S.VoucherNo
WHERE SD.SubmitDate BETWEEN '10/17/2002' AND
DATEADD(dd,1,'12/17/2002') AND V.InsCo IN (SELECT 'Patient' AS Code UNION SELECT Code FROM InsCompanies) AND
(V.TotChg > 0) AND V.DrCode IN (SELECT Code FROM Doctors) ORDER BY DrCode, V.InsCo, LastName, FirstName, V.VoucherNo

Query 2:
SELECT P.*, (SELECT MAX(ServiceDate) FROM VouchersDetail WHERE Voucher = V.VoucherNo) AS ServiceDate, V.*, S.*, S.Insco AS
SubmitInsCo FROM Patients P INNER JOIN Vouchers V INNER JOIN Submissions S ON V.VoucherNo = S.VoucherNo ON P.ID = V.PatID
WHERE (SELECT MAX(SubmitDate) FROM Submissions WHERE VoucherNo = V.VoucherNo) BETWEEN '10/17/2002' AND
DATEADD(dd,1,'12/17/2002') AND V.InsCo IN (SELECT 'Patient' AS Code UNION SELECT Code FROM InsCompanies) AND
(V.TotChg > 0) AND V.DrCode IN (SELECT Code FROM Doctors) ORDER BY DrCode, V.InsCo, LastName, FirstName, V.VoucherNo


Sarah Berger MCSD
   

- Advertisement -