dbTalk Databases Forums  

SQL Query Help

comp.databases.paradox comp.databases.paradox


Discuss SQL Query Help in the comp.databases.paradox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rey
 
Posts: n/a

Default SQL Query Help - 03-09-2006 , 05:55 PM






Howdy all.

Have a Pdox qbe that has been converted to SQL that sums transactions where
transaction date is > than the user selected date (EfftvDate).
However, it returns nothing/blank entry for both fields - acutally 0.00 in
FutureTrans when using CAST - and is the only record in the Answer table
while the Pdox QBE returns no records.
Both fields report true when checked via IsSpace function.

Appreciate your suggestions/comments as I'd like the results to be the same
as the Pdox qbe - no record. Probably missing something...8-)

Thanks,
Rey

Below is the orig QBE, the converted one and the query broken into 2
queries.
; creates :PRIV:dqsetup4

query
; creates riv:dqsetup4

:PRIVQSETUP1 | UnitNumFK | TranDate | Amount |
Quote:
Check | >_join1 | calc sum as
FutureTrans |

:PRIV:USERACTV | FirstFlag | EfftvDate |
Quote:
1 | _join1 |
EndQuery

Converted query:
; creates riv:dqsetup4
SELECT DISTINCT D.UnitNumFK,
CAST(SUM( D.Amount ) AS NUMERIC)
FutureTrans
FROM ":PRIVQSETUP1" D
INNER JOIN ":PRIV:USERACTV" U
ON (D.TranDate > U.EfftvDate)
WHERE U.FirstFlag = '1'
GROUP BY D.UnitNumFK
ORDER BY D.UnitNumFK

2 separate queries:
; creates riv:A1
SELECT D.UnitNumFK,
D.Amount, D.trandate
FROM ":PRIVQSETUP1" D
INNER JOIN ":PRIV:USERACTV" U
ON (D.TranDate > U.EfftvDate)
WHERE U.FirstFlag = '1'
GROUP BY D.UnitNumFK, d.Amount, D.Trandate
ORDER BY D.UnitNumFK

; creates riv:dqsetup4
SELECT DISTINCT D.UnitNumFK,
SUM( D.Amount ) FutureTrans
FROM ":PRIV:A1" D
GROUP BY D.UnitNumFK, D.Amount
ORDER BY D.UnitNumFK




Reply With Quote
  #2  
Old   
Larry DiGiovanni
 
Posts: n/a

Default Re: SQL Query Help - 03-09-2006 , 08:07 PM






Rey wrote:

Quote:
Appreciate your suggestions/comments as I'd like the results to be the
same as the Pdox qbe - no record. Probably missing something...8-)
I can confirm this behavior and it looks like a bug. The workaround in your
case is to include HAVING SUM(D.Amount) IS NOT NULL, which will exclude that
NULL row from the result. Try it and see.

I don't see this in Bertil's buglist. Create a Local SQL query like:

SELECT CustID, SUM(OrderTotal) SumOrders
FROM orders
WHERE CustID = 45 /*Non existent customer */
GROUP BY CustID

Produces a one row answer table with a blank CustId and SumOrders.

--
Larry DiGiovanni
Digico, Inc.
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources.



Reply With Quote
  #3  
Old   
Bertil Isberg
 
Posts: n/a

Default Re: SQL Query Help - 03-10-2006 , 05:11 AM



Larry
<<
I can confirm this behavior and it looks like a bug.
Quote:
It's not a bug, it's SQL. Count() and Sum() should, unless told to do
otherwise, return a single row. For count() it's obvious.

select count(*)
from Customer
where Country='XYZ'

should return a row with 0.

Sum() returns a row with a null value if no rows satisfies the where clause.

The only way to restrict the resultset to be empty is with a having clause.

If there's a bug, it's in the QBE.



--
Bertil Isberg
CTECH
Paradox Buglist: http://web.comhem.se/~u82608896/

remove spamfilter (reversed) to reply


Reply With Quote
  #4  
Old   
Larry DiGiovanni
 
Posts: n/a

Default Re: SQL Query Help - 03-10-2006 , 07:08 AM



Bertil Isberg wrote:

Quote:
select count(*)
from Customer
where Country='XYZ'

should return a row with 0.

Yes, but

select Country, count(*)
from Customer
where Country='XYZ'
group by Country

Should return no rows at all. This is what I am saying.

--
Larry DiGiovanni
Digico, Inc.
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources.



Reply With Quote
  #5  
Old   
Bertil Isberg
 
Posts: n/a

Default Re: SQL Query Help - 03-10-2006 , 08:22 AM



Larry

OK, Local SQL implements this differently than real databases do. But
Local SQL is consistent, which the QBE isn't. This query returns one row

Query
ANSWER: :PRIV:ANSWER.DB

Customer.DB | Customer No | City | Country |
Quote:
calc count | A | Check |
EndQuery

but not this one

Query
ANSWER: :PRIV:ANSWER.DB

Customer.DB | Customer No | City | Country |
Quote:
calc sum | A | Check |
EndQuery


Both SQL statements returns a single row.



--
Bertil Isberg
CTECH
Paradox Buglist: http://web.comhem.se/~u82608896/

remove spamfilter (reversed) to reply


Reply With Quote
  #6  
Old   
Larry DiGiovanni
 
Posts: n/a

Default Re: SQL Query Help - 03-10-2006 , 08:37 AM



Bertil Isberg wrote:

Quote:
Local SQL is consistent, which the QBE isn't.
Then there are two bugs.

The difference in the GROUP BY is a problem worth noting because, when
converting from one to the other, logic that depends on a NULL result set
will break unless a workaround is applied.

--
Larry DiGiovanni
Digico, Inc.
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources.




Reply With Quote
  #7  
Old   
Bertil Isberg
 
Posts: n/a

Default Re: SQL Query Help - 03-12-2006 , 05:16 AM



Larry
<<
when
converting from one to the other, logic that depends on a NULL result set
will break unless a workaround is applied.
Quote:
There's no guarantee that a Paradox query translated to SQL by Paradox will
return the same resultset. Especially when handling nulls. Here's another
example: "When a QBE with a "NOT value" criteria is translated to SQL, you
get Column<>value. The QBE condition will select blank values, but the SQL
condition won't. To get the same result in SQL as in QBE, you have to change
the code to NOT(Column=value). "




--
Bertil Isberg - CTECH
Paradox buglist:
online: http://web.comhem.se/~u82608896/

"Larry DiGiovanni" <nospam (AT) nospam (DOT) com> skrev i meddelandet
news:44118e61 (AT) pnews (DOT) thedbcommunity.com...
Quote:
Bertil Isberg wrote:

Local SQL is consistent, which the QBE isn't.

Then there are two bugs.

The difference in the GROUP BY is a problem worth noting because, when
converting from one to the other, logic that depends on a NULL result set
will break unless a workaround is applied.

--
Larry DiGiovanni
Digico, Inc.
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources.





Reply With Quote
  #8  
Old   
Larry DiGiovanni
 
Posts: n/a

Default Re: SQL Query Help - 03-12-2006 , 08:12 AM



Bertil Isberg wrote:

Quote:
There's no guarantee that a Paradox query translated to SQL by Paradox
will return the same resultset. Especially when handling nulls.
Sure. It's just particularly unexpected to see a row where none is matched.

--
Larry DiGiovanni
Digico, Inc.
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources.



Reply With Quote
  #9  
Old   
Bertil Isberg
 
Posts: n/a

Default Re: SQL Query Help - 03-12-2006 , 01:39 PM



Larry
<<
It's just particularly unexpected to see a row where none is matched.
Quote:
To restrict the rows participating in an aggregate, you use the WHERE clause
To restrict the resultset, you use the HAVING clause.

Local SQL only accepts aggregate functions in the HAVING clause.

select country, count(*)
from customer
where Stateprov"='HI'
group by country
having country='xx'

is not allowed

but

select country, count(*)
from customer
where Stateprov='HI'
group by country
having min(country)='xx'

is accepted.



--
Bertil Isberg - CTECH
Paradox buglist:
online: http://web.comhem.se/~u82608896/

"Larry DiGiovanni" <nospam (AT) nospam (DOT) com> skrev i meddelandet
news:44142b7c$1 (AT) pnews (DOT) thedbcommunity.com...
Quote:
Bertil Isberg wrote:

There's no guarantee that a Paradox query translated to SQL by Paradox
will return the same resultset. Especially when handling nulls.

Sure. It's just particularly unexpected to see a row where none is
matched.

--
Larry DiGiovanni
Digico, Inc.
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources.




Reply With Quote
  #10  
Old   
Larry DiGiovanni
 
Posts: n/a

Default Re: SQL Query Help - 03-12-2006 , 04:45 PM



Bertil Isberg wrote:

Quote:
To restrict the resultset, you use the HAVING clause.
Right.

--
Larry DiGiovanni
Digico, Inc.
IT Consulting and Staffing Solutions
www.digicoinc.com
Check out www.thedbcommunity.com for Paradox resources.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.