Home > Archive > FoxPro Help and Support > January 2006 > a little SQL help









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 a little SQL help
LeAnne

2006-01-07, 8:24 pm

In SQL Server 2000,
can I do something similar to the following?

DECLARE @TableName CHAR(8)
SET @TableName = 'Contacts'
SELECT * FROM @TableName

What i need to bascically be able to do is to leave the name of the table a
variable.
Because i have around 6 tables with the same structure, but depeding on a
certain condition i need to do something.
And I can't be duplicating the code for all the tables. I need to make it
generic by making the table name too a variable.


Jack Jackson

2006-01-07, 8:24 pm

On Sun, 8 Jan 2006 11:30:03 +1100, "LeAnne" <Anne@bogusemail.com>
wrote:

>In SQL Server 2000,
>can I do something similar to the following?
>
>DECLARE @TableName CHAR(8)
>SET @TableName = 'Contacts'
>SELECT * FROM @TableName
>
>What i need to bascically be able to do is to leave the name of the table a
>variable.
>Because i have around 6 tables with the same structure, but depeding on a
>certain condition i need to do something.
>And I can't be duplicating the code for all the tables. I need to make it
>generic by making the table name too a variable.
>


Since this is a VFP newsgroup, I assume you are fetching data from
VFP.

You can build the SELECT statement on the fly and use SQLExec:

cSQL = "SELECT * FROM " + cTableName
SQLExec(nHandle, cSQL, cAliasName)
LeAnne

2006-01-07, 8:24 pm

Thanks, but i'm sorry this is an SQL Server 2000 question.
I'm sorry this is the wrong area for this posting.

"Jack Jackson" < jacknospam@pebblerid
ge.com> wrote in message
news:vtn0s156istkrap
jbkn41f12soemasjl3g@
4ax.com...
> On Sun, 8 Jan 2006 11:30:03 +1100, "LeAnne" <Anne@bogusemail.com>
> wrote:
>
>
> Since this is a VFP newsgroup, I assume you are fetching data from
> VFP.
>
> You can build the SELECT statement on the fly and use SQLExec:
>
> cSQL = "SELECT * FROM " + cTableName
> SQLExec(nHandle, cSQL, cAliasName)



Cindy Winegarden

2006-01-08, 3:23 am

Hi Anne,

Try a microsoft.public.sqlserver.* newsgroup - probably the programming
newsgroup- on this same news server.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
cindy_winegarden@msn
.com www.cindywinegarden.com


"LeAnne" <Anne@bogusemail.com> wrote in message
news:OglU35%23EGHA.3984@TK2MSFTNGP14.phx.gbl...
> Thanks, but i'm sorry this is an SQL Server 2000 question.
> I'm sorry this is the wrong area for this posting.



Alan Sheffield

2006-01-09, 9:24 am

This should do it

DECLARE @TableName CHAR(8)
DECLARE @lcSql as varchar(2000)
SET @TableName = 'Contacts'
set @lcSql = 'SELECT * FROM '+ @TableName
EXEC(@lcSQL)
GO


Alan

"LeAnne" <Anne@bogusemail.com> wrote in message
news:eUg1tq%23EGHA.2648@TK2MSFTNGP11.phx.gbl...
> In SQL Server 2000,
> can I do something similar to the following?
>
> DECLARE @TableName CHAR(8)
> SET @TableName = 'Contacts'
> SELECT * FROM @TableName
>
> What i need to bascically be able to do is to leave the name of the table
> a variable.
> Because i have around 6 tables with the same structure, but depeding on a
> certain condition i need to do something.
> And I can't be duplicating the code for all the tables. I need to make it
> generic by making the table name too a variable.
>
>




Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com