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
 SQL Server Development (2000)
 Why Does it Always return NULLs?

Author  Topic 

Blastrix
Posting Yak Master

208 Posts

Posted - 2002-01-17 : 09:54:28
I have the following query, and no matter what I do to it, it seems to return NULLs for the TransTiers, and the DiscTiers. All the other columns get returned appropriately. I have triple checked that there is indeed data in the DB for the items. I can't understand why this is happening. Below is the code:

 
SELECT
BM.MerchantID,
M.MerchantName,
TotalSold,
TotalTransactions,
TR.TransTierStart,
TR.TransTierEnd,
TR.TransTierRate,
TD.DiscTierStart,
TD.DiscTierEnd,
TD.DiscTierRate,
RR.ChargebackRate,
RR.CreditRate

FROM
tblBrokerMerchants BM
LEFT OUTER JOIN tblMerchants M
ON BM.MerchantID = M.MerchantID
LEFT OUTER JOIN
(
SELECT
MerchantID,
SUM(Amount) AS TotalSold,
COUNT(*) AS TotalTransactions
FROM
tblOrders
WHERE
OrderDate >= @StartDate
AND OrderDate <= @EndDate
GROUP BY
MerchantID
) AS tOrders
ON BM.MerchantID = tOrders.MerchantID
LEFT OUTER JOIN tblTransactionRates TR
ON BM.MerchantID = TR.MerchantID
AND TR.UserTypeID = 2
AND TR.TransTierStart <= tOrders.TotalTransactions
AND TR.TransTierEnd >= tOrders.TotalTransactions
LEFT OUTER JOIN tblDiscountRates TD
ON BM.MerchantID = TD.MerchantID
AND TD.UserTypeID = 2
AND TD.DiscTierStart <= tOrders.TotalSold
AND TD.DiscTierEnd >= tOrders.TotalSold
LEFT OUTER JOIN tblReturnRates RR
ON BM.MerchantID = RR.MerchantID
AND RR.UserTypeID = 2

WHERE
BM.BrokerID = @BrokerID
ORDER BY
M.MerchantName


Thanks

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-01-17 : 10:01:52
it has to be to do with your data....or more accurately your condition for selectioning the data....

try leaving out the part below and it's "TD" equivalent....
"AND TR.TransTierStart <= tOrders.TotalTransactions AND TR.TransTierEnd >= tOrders.TotalTransactions"

does anything come back....?



also does the tOrders resultset return more than one answer(record)?....and how are you correlating the answer in it to the rest of the query....i don't see a join to a specific merchant in this subset....

Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-01-17 : 10:11:23
Does this make any difference?

[...]
LEFT OUTER JOIN tblTransactionRates TR
ON tOrders.MerchantID = TR.MerchantID
AND TR.UserTypeID = 2
AND TR.TransTierStart <= tOrders.TotalTransactions
AND TR.TransTierEnd >= tOrders.TotalTransactions
LEFT OUTER JOIN tblDiscountRates TD
ON tOrders.MerchantID = TD.MerchantID
AND TD.UserTypeID = 2
AND TD.DiscTierStart <= tOrders.TotalSold
AND TD.DiscTierEnd >= tOrders.TotalSold
[...]



Go to Top of Page

Blastrix
Posting Yak Master

208 Posts

Posted - 2002-01-17 : 10:30:40
Nice one Arnold! That did it perfectly.

One more question if you will...is there any way to clean up that query, or is that really the best it's going to get? There's more to the procedure, it goes on to insert these values into a temp table, then it multiplies TotalSold with TransTierRate, and TotalTransaction with DiscTierRate, and some other calculations. Is there any way to do that all with one SELECT statement, or do I need to do it with the temp table?

Go to Top of Page
   

- Advertisement -