Re: Setting sql result to global variable?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Darren Green (darren.green_at_reply-to-newsgroup-sqldts.com)
Date: 07/14/04


Date: Wed, 14 Jul 2004 16:35:17 +0100

Hmm, you do know that you could do all of that in T-SQL? Makes my eyes hurt
trying to look at it! Yes I know it works....

To get a value out of a task, then you need to use a resultset, so just use
SELECT 'TableNameXX' AS TableName as the last statement or thereabouts.

I suspect the design-time validation will fail, so use the workaround, of
some dummy SQL to set-up the parameter mapping, then the real SQL will get
stuffed in at run-time by your script task. The technique is described in
the "Input and Output Parameters" section of this article.

I also suggest you use SET NOCOUNT ON at the top of your script, also
described in the article.

Global Variables and Stored Procedure Parameters
(http://www.sqldts.com/default.aspx?234)

-- 
Darren Green
http://www.sqldts.com
"Sayonara" <me@msn.com> wrote in message
news:2ll0mpFe2sacU1@uni-berlin.de...
> Hey all,
>
> .The below code is included in the "Use ActiveX Script" area of an
"Execute
> SQL Task" in DTS. I know it's a sloppy loop, but I'm a newbie, and it
works,
> so... Anyways, the sqlstatement checks if a table exists, if it does, it
> appends an "a" to the tablename and creates a new table, if "a" table
exists
> as well, then it creates a "b" table and so on...
>
> What I'm trying to do is set a dts global variable equal to whatever table
> is eventually produced. Any tips or links are greatly appreciated! Thanks!
>
>
> Function Main()
>
>  Dim sqlstatement, objPkg, ExecSQL
>
>  sqlstatement = "IF object_id('dbo.de_"& dtname() &"') IS NULL CREATE
TABLE
> [de_"& dtname() &"] (tables,etc...) ON [PRIMARY] ELSE IF
> object_id('dbo.de_"& dtname() &"a') IS NULL CREATE TABLE [de_"& dtname()
> &"a] (tables,etc...) ON [PRIMARY] ELSE IF object_id('dbo.de_"& dtname()
> &"b') IS NULL CREATE TABLE [de_"& dtname() &"b] (tables,etc...) ON
[PRIMARY]
> ELSE IF object_id('dbo.de_"& dtname() &"c') IS NULL CREATE TABLE [de_"&
> dtname() &"c] (tables,etc...) ON [PRIMARY] ELSE IF object_id('dbo.de_"&
> dtname() &"d') IS NULL CREATE TABLE [de_"& dtname() &"d] (tables,etc...)
ON
> [PRIMARY] ELSE IF object_id('dbo.de_"& dtname() &"e') IS NULL CREATE TABLE
> [de_"& dtname() &"e] (tables,etc...) ON [PRIMARY] ELSE IF
> object_id('dbo.de_"& dtname() &"f') IS NULL CREATE TABLE [de_"& dtname()
> &"f] (tables,etc...) ON [PRIMARY] ELSE IF object_id('dbo.de_"& dtname()
> &"g') IS NULL CREATE TABLE [de_"& dtname() &"g] (tables,etc...) ON
> [PRIMARY]"
>
>
>  ' Whatever table is eventually created above is what I wish to set the
> global variable Raw_Table to
>
>  DTSGlobalVariables("Raw_Table").Value =
>
>
>  ' Getting sql script to execute
>
>  Set objPkg = DTSGlobalVariables.Parent
>  Set ExecSQL = objPkg.Tasks("DTSTask_DTSExecuteSQLTask_1").CustomTask
>  ExecSQL.SQLStatement = sqlstatement
>
> ' Reset object variables
>
>  Set ExecSQL = Nothing
>  Set objPkg = Nothing
>
>  Main = DTSTaskExecResult_Success
>
> End Function
>
>
> ' Creates date-based name for table, ex., "de_0101"
> Function dtname()
>  Dim d
>  d = date()
>  d = Right("0" & Month(d), 2) & Right("0" & Day(d), 2)
>  dtname = d
> End Function
>
>


Relevant Pages

  • Re: Vista hosting XPe tools/db
    ... Are you running this script on the machine that actually has the SQL server ... machine hosting the database. ... i don't know if you can install a second instance of SQL ...
    (microsoft.public.windowsxp.embedded)
  • Re: ActiveX script works in DTS but not in job, why?
    ... Account that SQL Agent runs under and it is a Local Admin on the box. ... As another test I saved the script as a .vbs file and tried running it, ... Microsoft OLE DB Provider for SQL Server ... that would be since I need to be able to load DTS packages from either a SQL ...
    (microsoft.public.sqlserver.dts)
  • Re: Enterprise Manager Newbie Question
    ... a SQL backup is not a simple copy of the database files. ... Is it possible to write a script that one could run from a workstation and ...
    (microsoft.public.sqlserver.tools)
  • Re: Vista hosting XPe tools/db
    ... here's an alternative script using the Microsoft ADO as ... opposed to the SQL DMO - this should allow this script to work ... Microsoft Windows XP Embedded Test Team ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.windowsxp.embedded)
  • Re: SQL Security
    ... except I'm having problems making it work in a script. ... ;Set properties of DB objects and open connection to database ... > from Books Online (within the SQL Server program group): ... > communicate with SQL Server. ...
    (microsoft.public.sqlserver.server)