dbTalk Databases Forums  

sql query result to variable

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss sql query result to variable in the comp.databases.xbase.fox forum.



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

Default sql query result to variable - 04-22-2004 , 01:18 AM






Hi,

I have a query statement like
select max(cust_id) from customer
I want to store the result into a variable. How can I achieve this ?

But if I use like "select max(cust_id) from customer into array
maxValue", When customer database is blank, the result will be zero, but
it is not storing zero into maxValue, If I have atleast one record in
the database, it stores the result into maxValue.

I have coded in the cmdAdd.Click and when the customer database has zero
record
IF THIS.caption = \<Add"
maxValue = 0
select max(cust_id) from customer into array maxValue
maxValue = maxValue + 1
ENDIF
thisform.cust_id1.text1.value=maxValue
dodefault()

It is throwing an error saying that maxValue is not an array. But this
code works fine if I have atleast one record.

Basically I want to achive this... I have form created using form
wizard, when I run the form the cust_id should get incremented
automatically when I click "Add" button.

Thanks in Advance.
Ashok



Reply With Quote
  #2  
Old   
Les Farnell
 
Posts: n/a

Default Re: sql query result to variable - 04-22-2004 , 01:48 AM






Ashok wrote:
Quote:
Hi,

I have a query statement like
select max(cust_id) from customer
I want to store the result into a variable. How can I achieve this ?

But if I use like "select max(cust_id) from customer into array
maxValue", When customer database is blank, the result will be zero, but
it is not storing zero into maxValue, If I have atleast one record in
the database, it stores the result into maxValue.

I have coded in the cmdAdd.Click and when the customer database has zero
record
IF THIS.caption = \<Add"
maxValue = 0
select max(cust_id) from customer into array maxValue
maxValue = maxValue + 1
ENDIF
thisform.cust_id1.text1.value=maxValue
dodefault()

It is throwing an error saying that maxValue is not an array. But this
code works fine if I have atleast one record.
Really? It looks like a type mismatch to me.

DIMENSION maxValue(1)
maxValue(1)=0

etc ought to work
Quote:
Basically I want to achive this... I have form created using form
wizard, when I run the form the cust_id should get incremented
automatically when I click "Add" button.

Thanks in Advance.
Ashok




Reply With Quote
  #3  
Old   
Stefan Wuebbe
 
Posts: n/a

Default Re: sql query result to variable - 04-22-2004 , 03:31 AM



You can also evaluate _tally after the Select Max() ... statement.

hth
-Stefan

"Ashok" <asjayara (AT) cisco (DOT) com> schrieb im Newsbeitrag
news:408763CE.7050209 (AT) cisco (DOT) com...
Quote:
Hi,

I have a query statement like
select max(cust_id) from customer
I want to store the result into a variable. How can I achieve this ?

But if I use like "select max(cust_id) from customer into array
maxValue", When customer database is blank, the result will be zero, but
it is not storing zero into maxValue, If I have atleast one record in
the database, it stores the result into maxValue.

I have coded in the cmdAdd.Click and when the customer database has zero
record
IF THIS.caption = \<Add"
maxValue = 0
select max(cust_id) from customer into array maxValue
maxValue = maxValue + 1
ENDIF
thisform.cust_id1.text1.value=maxValue
dodefault()

It is throwing an error saying that maxValue is not an array. But this
code works fine if I have atleast one record.

Basically I want to achive this... I have form created using form
wizard, when I run the form the cust_id should get incremented
automatically when I click "Add" button.

Thanks in Advance.
Ashok




Reply With Quote
  #4  
Old   
Ashok
 
Posts: n/a

Default Re: sql query result to variable - 04-22-2004 , 09:50 PM



Thanks Farnell, It works fine with your suggestion....


Les Farnell wrote:

Quote:
Ashok wrote:

Hi,

I have a query statement like
select max(cust_id) from customer
I want to store the result into a variable. How can I achieve this ?

But if I use like "select max(cust_id) from customer into array
maxValue", When customer database is blank, the result will be zero,
but it is not storing zero into maxValue, If I have atleast one
record in the database, it stores the result into maxValue.

I have coded in the cmdAdd.Click and when the customer database has
zero record
IF THIS.caption = \<Add"
maxValue = 0
select max(cust_id) from customer into array maxValue
maxValue = maxValue + 1
ENDIF
thisform.cust_id1.text1.value=maxValue
dodefault()

It is throwing an error saying that maxValue is not an array. But
this code works fine if I have atleast one record.


Really? It looks like a type mismatch to me.

DIMENSION maxValue(1)
maxValue(1)=0

etc ought to work


Basically I want to achive this... I have form created using form
wizard, when I run the form the cust_id should get incremented
automatically when I click "Add" button.

Thanks in Advance.
Ashok





Reply With Quote
  #5  
Old   
Ashok
 
Posts: n/a

Default Re: sql query result to variable - 04-22-2004 , 10:08 PM



Hi Stefan,

Thanks .. Can you give me an example, how to use this ..

-Ashok

Stefan Wuebbe wrote:

Quote:
You can also evaluate _tally after the Select Max() ... statement.

hth
-Stefan

"Ashok" <asjayara (AT) cisco (DOT) com> schrieb im Newsbeitrag
news:408763CE.7050209 (AT) cisco (DOT) com...


Hi,

I have a query statement like
select max(cust_id) from customer
I want to store the result into a variable. How can I achieve this ?

But if I use like "select max(cust_id) from customer into array
maxValue", When customer database is blank, the result will be zero, but
it is not storing zero into maxValue, If I have atleast one record in
the database, it stores the result into maxValue.

I have coded in the cmdAdd.Click and when the customer database has zero
record
IF THIS.caption = \<Add"
maxValue = 0
select max(cust_id) from customer into array maxValue
maxValue = maxValue + 1
ENDIF
thisform.cust_id1.text1.value=maxValue
dodefault()

It is throwing an error saying that maxValue is not an array. But this
code works fine if I have atleast one record.

Basically I want to achive this... I have form created using form
wizard, when I run the form the cust_id should get incremented
automatically when I click "Add" button.

Thanks in Advance.
Ashok










Reply With Quote
  #6  
Old   
Stefan Wuebbe
 
Posts: n/a

Default Re: sql query result to variable - 04-23-2004 , 01:37 AM



Hi Ashok,

_tally is a useful Vfp system variable containing the last SQL
statement's rowcount result:
CREATE CURSOR temp (testfield I)
SELECT MAX(testfield) FROM temp INTO ARRAY aTally
MESSAGEBOX(_tally)

INSERT INTO temp VALUES (10)
SELECT MAX(testfield) FROM temp INTO ARRAY aTally
MESSAGEBOX(_tally)

See also http://groups.google.com/advanced_group_search
for a lot of discussions and good examples.


hth
-Stefan

"Ashok" <asjayara (AT) cisco (DOT) com> schrieb im Newsbeitrag
news:408888BE.7020902 (AT) cisco (DOT) com...
Quote:
Hi Stefan,

Thanks .. Can you give me an example, how to use this ..

-Ashok

Stefan Wuebbe wrote:

You can also evaluate _tally after the Select Max() ... statement.

hth
-Stefan

"Ashok" <asjayara (AT) cisco (DOT) com> schrieb im Newsbeitrag
news:408763CE.7050209 (AT) cisco (DOT) com...


Hi,

I have a query statement like
select max(cust_id) from customer
I want to store the result into a variable. How can I achieve this ?

But if I use like "select max(cust_id) from customer into array
maxValue", When customer database is blank, the result will be zero, but
it is not storing zero into maxValue, If I have atleast one record in
the database, it stores the result into maxValue.

I have coded in the cmdAdd.Click and when the customer database has zero
record
IF THIS.caption = \<Add"
maxValue = 0
select max(cust_id) from customer into array maxValue
maxValue = maxValue + 1
ENDIF
thisform.cust_id1.text1.value=maxValue
dodefault()

It is throwing an error saying that maxValue is not an array. But this
code works fine if I have atleast one record.

Basically I want to achive this... I have form created using form
wizard, when I run the form the cust_id should get incremented
automatically when I click "Add" button.

Thanks in Advance.
Ashok











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.