Sunday, March 11, 2012
Dynamic generation of table name
My question is: is it possible to put in the FROM clause of a SELECT statement anything other than a string describing the name of a table in the database, and more specifically, a sub-query? Let's say I have a table with a known name that contains two columns, and I want to use the concatenation of the contents of those two columns to build the names of some tables, which will then be used in the FROM clause of another SELECT statement. Is that possible and how can I do that? Thanks in advance!
KamenFor end-users: NO, for Developers you can use dynamic SQL. :shocked:
Maybe for the end-users you could create a synonym for these tables, for example: every time you create a new table, you could drop old synonym and create new pointing to new table. ;)|||Bummer... That's what I thought, looking at the SQL documentation. I guess they can always use some "programmable" client, such as MS Access. Thanks, anyway.
Kamen
Sunday, February 26, 2012
Dynamic Cursor Generation..
I have a probs with dynamic generation.
I am writing the probs
======================================
create proc test
as
declare @.query varchar(500)
set @.query = 'select * from table'
--------------
declare mycur Cursor for Select * from table |
open mycur |
--------------
but instate of above block how can I dynamically generate this query?
------------
declare mycur Cursor for exec (@.query) |
------------
Or tell me the way.
Regards
Arijit Chatterjeehi, the problem was not clear what u want to do dynamiclly.
if u want to ftech rows thru proc, u can code like
create proc test
as
use db
exec(select * from table)
this might work
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||On 4 Nov 2003 21:04:27 -0800, arijitchatterjee123@.yahoo.co.in (Arijit
Chatterjee) wrote:
>but instate of above block how can I dynamically generate this query?
>------------
>declare mycur Cursor for exec (@.query) |
>------------
The way I've done stuff like this in the past is to stuff the results
into a temp table and run a cursor off that.
Example:
declare @.SQLstring varchar(100)
create table #foo (foovar int)
select @.SQLString = 'select distinct foovar from footable'
insert into #foo exec(@.SQLString)
declare foo_cursor for select distinct foovar from #foo
etc.
Obviously you really want to do this type of stuff when there is no
other way around it.
>Or tell me the way.
>Regards
>Arijit Chatterjee