How to pass parameter to TQuery and retrieve value from TQuery

How to pass parameter to TQuery and retrieve value from TQuery

Post by pc » Sun, 31 Dec 1899 09:00:00



Hello

I have created a TQuery, SQLSumStockAmt, like this

Select Sum( Price * Qty) TotAmt
  From "stock.db" stock
Where PurId = :Pur_Id

Then in the Data Module, I assign the value to the parameter and open
the TQuery

  SQLSumStockAmt.Params[0].AsInteger := PurchasePurId.Value;
  SQLSumStockAmt.Open;

But when I  ShowMessage(IntToStr(Round(SQLSumStockAmtTotAmt.Value)));

The value is wrong!

What goes wrong?

pc

 
 
 

How to pass parameter to TQuery and retrieve value from TQuery

Post by Dan Brenna » Sun, 31 Dec 1899 09:00:00


Have you tried Select Sum( Price * Qty) AS TotAmt


>Hello

>I have created a TQuery, SQLSumStockAmt, like this

>Select Sum( Price * Qty) TotAmt
>  From "stock.db" stock
>Where PurId = :Pur_Id

>Then in the Data Module, I assign the value to the parameter and open
>the TQuery

>  SQLSumStockAmt.Params[0].AsInteger := PurchasePurId.Value;
>  SQLSumStockAmt.Open;

>But when I  ShowMessage(IntToStr(Round(SQLSumStockAmtTotAmt.Value)));

>The value is wrong!

>What goes wrong?

>pc

--
Dan Brennand
CMDC systems, inc.
Configuration Management and Document Control: Consulting, Software,
and the only comprehesive textbook on this subject.
visit us at www.cmdcsystems.com
[Remove the SPAM from my e-mail address]

 
 
 

How to pass parameter to TQuery and retrieve value from TQuery

Post by Steve Koters » Sun, 31 Dec 1899 09:00:00



>I have created a TQuery, SQLSumStockAmt, like this

>Select Sum( Price * Qty) TotAmt
>  From "stock.db" stock
>Where PurId = :Pur_Id

>Then in the Data Module, I assign the value to the parameter and open
>the TQuery

>  SQLSumStockAmt.Params[0].AsInteger := PurchasePurId.Value;
>  SQLSumStockAmt.Open;

>But when I  ShowMessage(IntToStr(Round(SQLSumStockAmtTotAmt.Value)));

>The value is wrong!

Wrong in what (specific) way? Result is a value of zero? A NULL value? A
nonzero value, but apparently from the wrong records?

Do you have the TQuery.DataSource property set to anything? Should not be,
unless this is the Detail table of a Master-Detail relationship.

Try using the same SQL statement, but viewing it in a visual data-aware
control. Is the result what you would expect?

Try expanding the SQL statement to include the PurID column in the SELECT
clause. (This also requires adding a GROUP BY, but just for this test
statement.) Is the value returned in the PurID column the expected one?

  SELECT SUM(Price * Qty) AS TotAmt
  FROM "stock.db"
  WHERE PurId = :Pur_Id

What is the result of using the value of the AsString property when
displaying the result set value with ShowMessage?

  ShowMessage(SQLSumStockAmtTotAmt.AsString);

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski         "Television is a medium because anything well done
Felton, CA             is rare."
                                                 -- Fred Allen (1894-1956)

 
 
 

1. TQuery in TQuery

Hi all!

Now I develop my first serious Delphi application.

I have one trouble:

When I trying join in query tables from different databases,
this is so slowly, so slowly...

First database - Visual FoxPro
Second database - Paradox

Sql:

Select <field1> FROM <VFP table> A
Where Not Exists (Select <field2> From <Paradox table> B
        Where B.<field2> = A.<field1>)

My solutions:

Divide this SQL on two SQL:
1. Select <field1> FROM <VFP table> A

2. Select <field1> FROM <Cursor> A
   Where Not Exists (Select <field2> From <Paradox table> B
        Where B.<field2> = A.<field1>)

In help I don't find any frase about this issue.

Can I do this and how (syntax, tips or any other )?

Or How can I do SQL faster ?

Waiting for you mail....with future grateful

2. TEXT truncation, SQL Server 7.0

3. TQuery from TQuery ??

4. Some information about Access 2000 and SQL Sever

5. Using TQuery in a TQuery??

6. SQL Maintenance Plan Error

7. Using TQuery in a TQuery?

8. read only forms

9. TQuery from another TQuery result??

10. TQuery on TQuery result set??

11. Result sets of a TQuery feed into another TQuery

12. Using Tquery results as input for an next TQuery

13. Retrieving a result set with a TQuery