|
Home > Archive > Getting Started with dBASE > October 2006 > Another Varible Question
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Another Varible Question
|
|
| Forrest Ganther 2006-10-25, 7:23 am |
| I would like to use a string plus a variable to
open a table.... for instance Book2.dbf
q.sql := "SELECT * from Book (plus the variable)"
I have a number of these tables to perform
similar operations upon.
I just don't know how to concatenate them,
or is it possible in dBase Plus?
In 5.7 I used USE BOOK&NUMBOOK
Thanks for any help
| |
| Frank J. Polan 2006-10-25, 7:23 am |
| Forrest
The code in the onOpen below is one way of doing it
...................
function form_onOpen
nVar = 2
cTable = 'Test'+nVar
this.query1.sql := "select * from '&cTable' "
this.query1.active := true
this.grid1.datalink := this.query1.rowset
return
................................................................
HTH
Frank Polan
On Fri, 22 Sep 2006 12:08:14 -0500, "Forrest Ganther"
< forrestganther@sbcgl
obal.net> wrote:
>I would like to use a string plus a variable to
>open a table.... for instance Book2.dbf
>
>q.sql := "SELECT * from Book (plus the variable)"
>
>I have a number of these tables to perform
>similar operations upon.
>
>I just don't know how to concatenate them,
>or is it possible in dBase Plus?
>
>In 5.7 I used USE BOOK&NUMBOOK
>
>Thanks for any help
>
| |
| Roland Wingerter 2006-10-25, 7:23 am |
| Forrest Ganther wrote
>
>I would like to use a string plus a variable to
> open a table.... for instance Book2.dbf
> q.sql := "SELECT * from Book (plus the variable)"
>
> I have a number of these tables to perform
> similar operations upon.
>
> I just don't know how to concatenate them,
> or is it possible in dBase Plus?
------
Try this in the command window:
nBook = 1
cName = "book"+ltrim(str(nBook))
? cName // "book1"
cSQL = "select * from "+cName
&cSQL
Likewise, you could redefine the sql property of your query.
Hope this helps
Roland
| |
| John Marshall 2006-10-25, 7:23 am |
|
Roland:
I have had a perplexing issue recently with parameters as well. I have used them to build SQL update, insert and delete statements sucessfully in several program areas, but recently I cannot seem to get one to go (below). I keep getting a "token" not
found error. Any thoughts?
SQLEdit = "Descr = '" + rtrim(form.entryfield2.value) + "', srt = " + form.entryfield3.value ;
+ ", strt = '" + form.entryfield4.value + "', stp = '" + form.entryfield5.value + "' " ;
+ "WHERE MPCode = '" + form.entryfield1.value + "'"
UPDATE :PRTIP:MP SET &SQLEdit
Thanks,
JM
Roland Wingerter Wrote:
> Forrest Ganther wrote
> ------
> Try this in the command window:
>
> nBook = 1
> cName = "book"+ltrim(str(nBook))
> ? cName // "book1"
> cSQL = "select * from "+cName
> &cSQL
>
> Likewise, you could redefine the sql property of your query.
>
> Hope this helps
>
> Roland
>
>
| |
| Roland Wingerter 2006-10-25, 7:23 am |
| John Marshall wrote
>
> I have had a perplexing issue recently with parameters as well. I have
> used them to build SQL update, insert and delete statements sucessfully in
> several program areas, but recently I cannot seem to get one to go
> (below). I keep getting a "token" not found error. Any thoughts?
>
>
> SQLEdit = "Descr = '" + rtrim(form.entryfield2.value) + "', srt = " +
> form.entryfield3.value ;
> + ", strt = '" + form.entryfield4.value + "', stp = '" +
> form.entryfield5.value + "' " ;
> + "WHERE MPCode = '" + form.entryfield1.value + "'"
>
> UPDATE :PRTIP:MP SET &SQLEdit
------
John,
your syntax should work in theory. But I think you have a better chance to
get helpful answers if you ask this in a new thread.
Roland
| |
| Ken Mayer [dBVIPS] 2006-10-25, 7:23 am |
| Forrest Ganther wrote:
> I would like to use a string plus a variable to
> open a table.... for instance Book2.dbf
>
> q.sql := "SELECT * from Book (plus the variable)"
This is simply a character string, so you can do this easily:
q.sql := "SELECT * from Book"+nVar
Although you might want to put the table in quotes ... I tend to do this:
q.sql := [SELECT * from 'Book]+n+[']
This ensures that for example, if I use a path for the table (there are
odd cases where it's simpler, such as importing data from a table in a
"once in awhile" situation, rather than daily). The brackets make it
easier to read than if I'd use double quotes.
Ken
--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/
*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/dbase/dBASEBook.htm
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase
| |
| John Marshall 2006-10-25, 7:23 am |
| I shall. The perplexing part of it is that the output result of the SQLUpdate string does in fact work if I use it verbatim in the update clause.
JM
Roland Wingerter Wrote:
> John Marshall wrote
> ------
> John,
>
> your syntax should work in theory. But I think you have a better chance to
> get helpful answers if you ask this in a new thread.
>
> Roland
>
>
>
>
>
| |
| Forrest Ganther 2006-10-25, 7:23 am |
| Thanks everyone!!! OOP sure makes me
feel dumb!
Really appreciate you replies!!!
"Ken Mayer [dBVIPS]" < dbase@_nospam_golden
stag.net> wrote in message
news:BpmT6un3GHA.252@news-server...
> Forrest Ganther wrote:
>
> This is simply a character string, so you can do this easily:
>
> q.sql := "SELECT * from Book"+nVar
>
> Although you might want to put the table in quotes ... I tend to do this:
>
> q.sql := [SELECT * from 'Book]+n+[']
>
> This ensures that for example, if I use a path for the table (there are
> odd cases where it's simpler, such as importing data from a table in a
> "once in awhile" situation, rather than daily). The brackets make it
> easier to read than if I'd use double quotes.
>
> Ken
>
> --
> /(Opinions expressed are purely my own, not those of dataBased
> Intelligence, Inc.)/
>
> *Ken Mayer* [dBVIPS]
> /Golden Stag Productions/
> dBASE at goldenstag dot net
> http://www.goldenstag.net/dbase/dBASEBook.htm
> http://www.goldenstag.net/GSP
> http://www.goldenstag.net/dbase
| |
|
|
|
|
|