Re: Dynamic SQL

From: ClairHolliday (clair_at_holliday1056.freeserve.co.uk)
Date: 05/25/03


Date: Sun, 25 May 2003 20:14:22 +0100


you could build the statement into a variable (@sql) and then execute the
variable (execute (@sql) this will give you 8000 characters to play with and
can apparently concatenate variables in the execute statement if 8000 isnt
enough

"Steve Thompson" <SteveThompson@nomail.please> wrote in message
news:#j8DC4VIDHA.336@tk2msftngp13.phx.gbl...
> Take a look at the sp_executesql stored procedure, this should do what you
> want.
>
> Steve
> "Shamim" <shamim.abdul@railamerica.com> wrote in message
> news:#djSnbTIDHA.452@TK2MSFTNGP11.phx.gbl...
> > SQL SERVER 2K
> >
> > Got a server with 15 databases, need to load data from 15 databases to a
> > common data-wearhouse database in the same server.
> >
> > Developed a SP with INSERT ,UPDATE statements to load data.
> > I want to dynamically change database name in my SQL statements.
> >
> > I created a table 'dbname' which stores all database name.
> > Inside my SP, using a CURSOR ,dynamically change the database name.
> >
> > My issue is , I have lengthy INSERT / UPDATE statements, how to make it
> > work using 'EXEC' statement ??
> >
> > For Example EXEC (' insert into xxxx
> > select 50 columns from ' + @dbname +
> > '.dbo.yyyyy')
> >
> > Any good approach to use EXEC for long SQL statements ?
>
>



Relevant Pages

  • Re: Opinions on approach, please...
    ... Create a data layer program per table, ... number of bind variable tokens in your dynamic SQL. ... then simply EXECUTE that without passing it any parameters? ... Hard code WHERE clauses. ...
    (comp.lang.cobol)
  • Re: SQL Injection- Bypassing magic_quotes
    ... Because i was trying to execute: ... Don't terminate the query and you most ... Or try something like bobcat or one of the other SQL injection tools out ... Chief Information Security Officer ...
    (Pen-Test)
  • Re: Opinions on approach, please...
    ... Create a data layer program per table, ... number of bind variable tokens in your dynamic SQL. ... then simply EXECUTE that without passing it any parameters? ... explicitly code dummy words as bind variable placekeepers, put the host variables on the ...
    (comp.lang.cobol)
  • Re: UPDATE query in Access 2003 raising error
    ... string into a variable strSQL but create the qrydef from a string strSQLx (I ... Runtime error 3066 Query must have at least one destination field. ... The SQL works fine if I use it in the QBF Design mode. ... Elsewhere in the code I use the same technique to execute an SQL ...
    (microsoft.public.access.formscoding)
  • Re: Poor performance when executing stored procedure
    ... > Generally I would write stored procedures to do only one job. ... If SQL Server ... > which is even worse those sps can execute each other. ... > then executed spOrders which is executed in spCustomers and then got stuck ...
    (microsoft.public.sqlserver.programming)