Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts

Wednesday, March 7, 2012

can I use sql profiler to debug stored procedure

can I use sql profiler to debug stored procedure, for example, when application runing, can I get infomation in profiler, such as value of variable in stored procedure, especially input parameter. Because I need to know what is value of input parameter I
get from client side. Thanks
Asked and answered in .programming group... Please do not multi-post.
"iter" <anonymous@.discussions.microsoft.com> wrote in message
news:17B8A330-6E4E-487A-9229-6493EF9DBBA5@.microsoft.com...
> can I use sql profiler to debug stored procedure, for example, when
application runing, can I get infomation in profiler, such as value of
variable in stored procedure, especially input parameter. Because I need to
know what is value of input parameter I get from client side. Thanks
>

Saturday, February 25, 2012

Can I use a variable to hold the target table name.

We need to pull from a table that is named tablename_mmddyy and populate a table with the same format tablename_mmddyy. The date will be different every month so I want to be able to build the tablenames every month. Is there a way to do this in SSIS? Thank you.Yes, using expressions in your variables, you can do what you want.

Create a variable and then for its properties, set EvaluateAsExpression to True and then build your expression accordingly in the Expression box.

Then in your OLE DB source/destination, you can use that variable as the table. Just know that you'll want to probably set DelayValidation to True on your connection managers when you do this.

There are plenty of examples in this forum if you search for them on how to build expressions, if you need.|||I found the option for this under Data Access Mode but we need to do the same thing for the database name which will be in a similar format e.g. databasename_mmddyy and the source db name will change every month.|||Same thing. You can use expressions on your connection managers to dynamically create the current connection string.|||The same principals can be applied to a connection manager (i.e. database name of database server). You can use an expression to build the connection string from a variable in the properties window of the connection manager.|||Any examples of this?|||

agentf1 wrote:

Any examples of this?

In the ConnectionString expression box for a connection manager. Also it can't hurt to set DelayValidation to True.

"Data Source=" + @.[User::YourDatabaseNameVariable] +";Initial Catalog=Report;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;"|||What goes in the database name field? I am assuming that it gets overridden by the expression.|||

agentf1 wrote:

What goes in the database name field? I am assuming that it gets overridden by the expression.

The ConnectionString will override any other parameters.|||

agentf1 wrote:

Any examples of this?

http://search.live.com/results.aspx?FORM=QBJK&q1=macro%3Ajamiet.ssis&q=expressions

-JT

|||This seems to be changing both of my OLE DB Connections. Is there a way one can be static and the other updated by the variable? It also appears that Data Source controls the server and Catalog is the database name.|||

agentf1 wrote:

This seems to be changing both of my OLE DB Connections. Is there a way one can be static and the other updated by the variable?

That's impossible (unless one of us has misunderstood). An expression on the ConnectionString property of a connection manager only changes that connection manager.

agentf1 wrote:

It also appears that Data Source controls the server and Catalog is the database name.

Correct.

-Jamie

|||

Jamie Thomson wrote:

agentf1 wrote:

This seems to be changing both of my OLE DB Connections. Is there a way one can be static and the other updated by the variable?

That's impossible (unless one of us has misunderstood). An expression on the ConnectionString property of a connection manager only changes that connection manager.

agentf1 wrote:

It also appears that Data Source controls the server and Catalog is the database name.

Correct.

-Jamie

My bad, I had the expression on both connections. I am OK, thanks for all the help, worked beautifully.

Can I use a table variable in sp_executesql for output

Can I use a table variable to gain output using the sp_executesql procedure?
Example:
Normally I might have something like:
DECLARE @.max varchar(9),@.sExec nvarchar(200)
SELECT @.sExec=N'SELECT @.max=(SELECT MAX(ID) FROM Parts)'
EXEC sp_executesql @.sExec, N'@.max varchar(9) OUTPUT', @.max OUTPUT
print @.max
--I'm doing something wrong... what?
--Instead can it be written to work like this?
DECLARE @.tmp TABLE(@.max varchar(9)null)
DECLARE @.sExec nvarchar(200)
SELECT @.sExec=N'INSERT INTO @.tmp =(SELECT Convert(varchar(9),ID) FROM Parts)'
N'@.tmp TABLE(@.max varchar(9)null) OUTPUT', @.tmp OUTPUT
SELECT Max(ID) FROM @.tmp
Regards,
Jamie
No but you can create a temp table before you call the sp_executesql and
access it from inside the dynamic sql. Those rows that you insert inside
the dynamic sql will still be there after the sp_executesql batch is done.
Andrew J. Kelly SQL MVP
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
> Can I use a table variable to gain output using the sp_executesql
> procedure?
> Example:
> Normally I might have something like:
> DECLARE @.max varchar(9),@.sExec nvarchar(200)
> SELECT @.sExec=N'SELECT @.max=(SELECT MAX(ID) FROM Parts)'
> EXEC sp_executesql @.sExec, N'@.max varchar(9) OUTPUT', @.max OUTPUT
> print @.max
> --I'm doing something wrong... what?
> --Instead can it be written to work like this?
> DECLARE @.tmp TABLE(@.max varchar(9)null)
> DECLARE @.sExec nvarchar(200)
> SELECT @.sExec=N'INSERT INTO @.tmp =(SELECT Convert(varchar(9),ID) FROM
> Parts)'
> N'@.tmp TABLE(@.max varchar(9)null) OUTPUT', @.tmp OUTPUT
> SELECT Max(ID) FROM @.tmp
> Regards,
> Jamie
|||Andrew,
Thanks for replying.
I am trying to get percentages of a single table for weighting.
If I understand right, then this should work for my first 60 percent of the
table.
DECLARE @.PercA varchar(2)
SELECT @.PercA='60'
DECLARE @.ITEMZ1 TABLE(item_no varchar(30))
SELECT @.SQL=N'(INSERT INTO @.ITEMZ1 SELECT TOP '+@.A+N' PERCENT L.item_no FROM
iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND L.item_no =
N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC)'
EXEC sp_executesql @.SQL, N'@.ITEMZ1 TABLE(item_no varchar(30)) OUTPUT',
@.ITEMZ1 OUTPUT
SELECT * FROM @.ITEMZ1
I'm missing something. Is it obvious?
Jamie
"Andrew J. Kelly" wrote:

> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
>
>
|||I found something similar - says it works in YUKON only.
http://www.c-sharpcorner.com/Longhor...ordInYukon.asp
This is what I really want. Is there a way to do this pre-YUKON?
DECLARE @.n AS int
SET @.n = 60
SELECT TOP(@.n)
L.item_no FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc
AND L.item_no = N.item_no
ORDER BY L.avg_cost * L.usage_ytd DESC
"Andrew J. Kelly" wrote:

> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
>
>
|||Suppose the tmptable needed to be created from a string variable fed into the
stored procedure:
The last line below does not work, but follows the same logic. Can a temp
table be created from an EXEC (@.SQL) statement?
DECLARE @.SQL nvarchar(4000),@.BeginPercent tinyint,@.EndPercent
tinyint,@.SQLLength int,@.FieldList varchar(4000),@.SQLTmpTbl
nvarchar(4000),@.ComputedField varchar(128)
SELECT @.SQL=N'SELECT
L.item_no,N.item_desc_1,N.item_desc_2,L.usage_ytd, L.avg_cost,L.inv_class,L.loc,L.prod_cat
FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND L.item_no
= N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC'
SELECT @.ComputedField=N'L.usage_ytd * L.avg_cost'
DECLARE @.SQLSelect nvarchar(4000),@.SQLFROM nvarchar(4000)
SELECT @.SQLSelect=dbo.instr(@.SQL,'FROM')
SELECT @.SQLFROM=REPLACE(@.SQL,@.SQLSelect,'')
SELECT @.FieldList=LTRIM(RTRIM(REPLACE(@.SQLSelect,'SELECT' ,'')))
SELECT @.FieldList=REPLACE(@.FieldList,',',' varchar(255),')
SELECT @.FieldList=@.FieldList+' nvarchar(255)'
SELECT @.SQLTmpTbl=N'DECLARE @.tmp TABLE('+@.Fieldlist+N')'
Print REPLACE(@.SQLTmpTbl,'.','_')
exec sp_executesql @.SQLTmpTbl
"Andrew J. Kelly" wrote:

> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
|||First of all that is a table variable and not a temp table. But in either
case it will not work as you expect. The scoping of variables and temp
tables that are created inside dynamic sql are limited to that execution
only. Once they are done the code outside of that dynamic batch will not
see those objects. Only if you create a temp table (not a table var)
outside of the dynamic sql batch will it be usable in the batch and then
again after the batch. Have a look at these:
http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
http://www.users.drew.edu/skass/sql/...leProc.sql.txt List to
Table script
http://www.support.microsoft.com/?id=262499 Using OutPut Params &
sp_executeSql
Andrew J. Kelly SQL MVP
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:BE8B9EC0-7CD2-4E71-BA09-C966895456D8@.microsoft.com...[vbcol=seagreen]
> Suppose the tmptable needed to be created from a string variable fed into
> the
> stored procedure:
> The last line below does not work, but follows the same logic. Can a
> temp
> table be created from an EXEC (@.SQL) statement?
> DECLARE @.SQL nvarchar(4000),@.BeginPercent tinyint,@.EndPercent
> tinyint,@.SQLLength int,@.FieldList varchar(4000),@.SQLTmpTbl
> nvarchar(4000),@.ComputedField varchar(128)
> SELECT @.SQL=N'SELECT
> L.item_no,N.item_desc_1,N.item_desc_2,L.usage_ytd, L.avg_cost,L.inv_class,L.loc,L.prod_cat
> FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND
> L.item_no
> = N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC'
> SELECT @.ComputedField=N'L.usage_ytd * L.avg_cost'
> DECLARE @.SQLSelect nvarchar(4000),@.SQLFROM nvarchar(4000)
> SELECT @.SQLSelect=dbo.instr(@.SQL,'FROM')
> SELECT @.SQLFROM=REPLACE(@.SQL,@.SQLSelect,'')
> SELECT @.FieldList=LTRIM(RTRIM(REPLACE(@.SQLSelect,'SELECT' ,'')))
> SELECT @.FieldList=REPLACE(@.FieldList,',',' varchar(255),')
> SELECT @.FieldList=@.FieldList+' nvarchar(255)'
> SELECT @.SQLTmpTbl=N'DECLARE @.tmp TABLE('+@.Fieldlist+N')'
> Print REPLACE(@.SQLTmpTbl,'.','_')
> exec sp_executesql @.SQLTmpTbl
>
> "Andrew J. Kelly" wrote:
|||That worked quite well. Thank you Andrew
"Andrew J. Kelly" wrote:

> First of all that is a table variable and not a temp table. But in either
> case it will not work as you expect. The scoping of variables and temp
> tables that are created inside dynamic sql are limited to that execution
> only. Once they are done the code outside of that dynamic batch will not
> see those objects. Only if you create a temp table (not a table var)
> outside of the dynamic sql batch will it be usable in the batch and then
> again after the batch. Have a look at these:
>
> http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
> http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
> http://www.users.drew.edu/skass/sql/...leProc.sql.txt List to
> Table script
> http://www.support.microsoft.com/?id=262499 Using OutPut Params &
> sp_executeSql
>
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:BE8B9EC0-7CD2-4E71-BA09-C966895456D8@.microsoft.com...
>
>

Can I use a table variable in sp_executesql for output

Can I use a table variable to gain output using the sp_executesql procedure?
Example:
Normally I might have something like:
DECLARE @.max varchar(9),@.sExec nvarchar(200)
SELECT @.sExec=N'SELECT @.max=(SELECT MAX(ID) FROM Parts)'
EXEC sp_executesql @.sExec, N'@.max varchar(9) OUTPUT', @.max OUTPUT
print @.max
--I'm doing something wrong... what?
--Instead can it be written to work like this?
DECLARE @.tmp TABLE(@.max varchar(9)null)
DECLARE @.sExec nvarchar(200)
SELECT @.sExec=N'INSERT INTO @.tmp =(SELECT Convert(varchar(9),ID) FROM Parts)
'
N'@.tmp TABLE(@.max varchar(9)null) OUTPUT', @.tmp OUTPUT
SELECT Max(ID) FROM @.tmp
Regards,
JamieNo but you can create a temp table before you call the sp_executesql and
access it from inside the dynamic sql. Those rows that you insert inside
the dynamic sql will still be there after the sp_executesql batch is done.
Andrew J. Kelly SQL MVP
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
> Can I use a table variable to gain output using the sp_executesql
> procedure?
> Example:
> Normally I might have something like:
> DECLARE @.max varchar(9),@.sExec nvarchar(200)
> SELECT @.sExec=N'SELECT @.max=(SELECT MAX(ID) FROM Parts)'
> EXEC sp_executesql @.sExec, N'@.max varchar(9) OUTPUT', @.max OUTPUT
> print @.max
> --I'm doing something wrong... what?
> --Instead can it be written to work like this?
> DECLARE @.tmp TABLE(@.max varchar(9)null)
> DECLARE @.sExec nvarchar(200)
> SELECT @.sExec=N'INSERT INTO @.tmp =(SELECT Convert(varchar(9),ID) FROM
> Parts)'
> N'@.tmp TABLE(@.max varchar(9)null) OUTPUT', @.tmp OUTPUT
> SELECT Max(ID) FROM @.tmp
> Regards,
> Jamie|||Andrew,
Thanks for replying.
I am trying to get percentages of a single table for weighting.
If I understand right, then this should work for my first 60 percent of the
table.
DECLARE @.PercA varchar(2)
SELECT @.PercA='60'
DECLARE @.ITEMZ1 TABLE(item_no varchar(30))
SELECT @.SQL=N'(INSERT INTO @.ITEMZ1 SELECT TOP '+@.A+N' PERCENT L.item_no FROM
iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND L.item_no =
N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC)'
EXEC sp_executesql @.SQL, N'@.ITEMZ1 TABLE(item_no varchar(30)) OUTPUT',
@.ITEMZ1 OUTPUT
SELECT * FROM @.ITEMZ1
I'm missing something. Is it obvious?
Jamie
"Andrew J. Kelly" wrote:

> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
>
>|||I found something similar - says it works in YUKON only.
http://www.c-sharpcorner.com/Longho...wordInYukon.asp
This is what I really want. Is there a way to do this pre-YUKON?
DECLARE @.n AS int
SET @.n = 60
SELECT TOP(@.n)
L.item_no FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc
AND L.item_no = N.item_no
ORDER BY L.avg_cost * L.usage_ytd DESC
"Andrew J. Kelly" wrote:

> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
>
>|||Suppose the tmptable needed to be created from a string variable fed into th
e
stored procedure:
The last line below does not work, but follows the same logic. Can a temp
table be created from an EXEC (@.SQL) statement?
DECLARE @.SQL nvarchar(4000),@.BeginPercent tinyint,@.EndPercent
tinyint,@.SQLLength int,@.FieldList varchar(4000),@.SQLTmpTbl
nvarchar(4000),@.ComputedField varchar(128)
SELECT @.SQL=N'SELECT
L.item_no,N.item_desc_1,N.item_desc_2,L.usage_ytd,L.avg_cost,L.inv_class,L.l
oc,L.prod_cat
FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND L.item_no
= N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC'
SELECT @.ComputedField=N'L.usage_ytd * L.avg_cost'
DECLARE @.SQLSelect nvarchar(4000),@.SQLFROM nvarchar(4000)
SELECT @.SQLSelect=dbo.instr(@.SQL,'FROM')
SELECT @.SQLFROM=REPLACE(@.SQL,@.SQLSelect,'')
SELECT @.FieldList=LTRIM(RTRIM(REPLACE(@.SQLSelec
t,'SELECT','')))
SELECT @.FieldList=REPLACE(@.FieldList,',',' varchar(255),')
SELECT @.FieldList=@.FieldList+' nvarchar(255)'
SELECT @.SQLTmpTbl=N'DECLARE @.tmp TABLE('+@.Fieldlist+N')'
Print REPLACE(@.SQLTmpTbl,'.','_')
exec sp_executesql @.SQLTmpTbl
"Andrew J. Kelly" wrote:

> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>|||First of all that is a table variable and not a temp table. But in either
case it will not work as you expect. The scoping of variables and temp
tables that are created inside dynamic sql are limited to that execution
only. Once they are done the code outside of that dynamic batch will not
see those objects. Only if you create a temp table (not a table var)
outside of the dynamic sql batch will it be usable in the batch and then
again after the batch. Have a look at these:
http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
http://www.users.drew.edu/skass/sql...bleProc.sql.txt List to
Table script
http://www.support.microsoft.com/?id=262499 Using OutPut Params &
sp_executeSql
Andrew J. Kelly SQL MVP
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:BE8B9EC0-7CD2-4E71-BA09-C966895456D8@.microsoft.com...[vbcol=seagreen]
> Suppose the tmptable needed to be created from a string variable fed into
> the
> stored procedure:
> The last line below does not work, but follows the same logic. Can a
> temp
> table be created from an EXEC (@.SQL) statement?
> DECLARE @.SQL nvarchar(4000),@.BeginPercent tinyint,@.EndPercent
> tinyint,@.SQLLength int,@.FieldList varchar(4000),@.SQLTmpTbl
> nvarchar(4000),@.ComputedField varchar(128)
> SELECT @.SQL=N'SELECT
> L.item_no,N.item_desc_1,N.item_desc_2,L.usage_ytd,L.avg_cost,L.inv_class,L
.loc,L.prod_cat
> FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND
> L.item_no
> = N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC'
> SELECT @.ComputedField=N'L.usage_ytd * L.avg_cost'
> DECLARE @.SQLSelect nvarchar(4000),@.SQLFROM nvarchar(4000)
> SELECT @.SQLSelect=dbo.instr(@.SQL,'FROM')
> SELECT @.SQLFROM=REPLACE(@.SQL,@.SQLSelect,'')
> SELECT @.FieldList=LTRIM(RTRIM(REPLACE(@.SQLSelec
t,'SELECT','')))
> SELECT @.FieldList=REPLACE(@.FieldList,',',' varchar(255),')
> SELECT @.FieldList=@.FieldList+' nvarchar(255)'
> SELECT @.SQLTmpTbl=N'DECLARE @.tmp TABLE('+@.Fieldlist+N')'
> Print REPLACE(@.SQLTmpTbl,'.','_')
> exec sp_executesql @.SQLTmpTbl
>
> "Andrew J. Kelly" wrote:
>|||That worked quite well. Thank you Andrew
"Andrew J. Kelly" wrote:

> First of all that is a table variable and not a temp table. But in either
> case it will not work as you expect. The scoping of variables and temp
> tables that are created inside dynamic sql are limited to that execution
> only. Once they are done the code outside of that dynamic batch will not
> see those objects. Only if you create a temp table (not a table var)
> outside of the dynamic sql batch will it be usable in the batch and then
> again after the batch. Have a look at these:
>
> http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
> http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
> http://www.users.drew.edu/skass/sql...bleProc.sql.txt List to
> Table script
> http://www.support.microsoft.com/?id=262499 Using OutPut Params &
> sp_executeSql
>
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:BE8B9EC0-7CD2-4E71-BA09-C966895456D8@.microsoft.com...
>
>

Sunday, February 19, 2012

Can I set Excel connection manager's data source as a variable?

I do not know the Excel file name to load in design time.

Would like to pass the value to a variable in the package in run time?

How to do this?

Thanks,

Guangming

Property Expressions is the feature you want. You can assign and expression to most properties, including the DataSource property of a connection. The expression would just be the name of your variable, e.g.

@.[User:MyVar]

Some UIs expose expressions as a separate tab, or just expand expressions from the normal properties grid.

|||I set ExcelFilePath to a variable:

varExcelFileFullPath.

I set an initial value ( \\test\testShare\aaab.xls ) to it when designing the package. It works

Later I run it inside SQL server as below. It failed.

exec xp_cmdshell 'dtexec /SQL "\NE_LoadExcel_Test_direct" /SERVER ** /USER ***** /PASSWORD ****

/CONNECTION "DataSource-Excel";"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\test\testshare\aaab2.xls;Extended Properties=""EXCEL 8.0;HDR=YES"";"

/CONNECTION "Test.NGAEarth";"Data Source=Test;Initial Catalog=NGAEarth;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;"

/MAXCONCURRENT " -1 " /CHECKPOINTING OFF /REPORTING EW /LOGGER "{6AA833A1-E4B2-4431-831B-DE695049DC61}";"Test.NGAEarth"

/set "\Package.Variables[User::varPreSQLAction].Properties[Value]";"delete from Features where type = ''aaab''"

/set "\Package.Variables[User::varExcelWorkbookName].Properties[Value]";"Sheet1$"

/set "\Package.Variables[User::varDestinationTableName].Properties[Value]";"Features"

/set "\Package.Variables[User::varExcelFileFullPath].Properties[Value]";"\\test\testShare\aaab2.xls"

'

Actually, I tried to change other variables. E.g., I changed the file name from aaab2.xls to aaab.xls, Excel worksheet name from Sheet1$ to Sheet2$.

It seems the package never get the parameters I set as above. It always gets the values I set in design time. The errors I got are:

Error: 2006-02-01 15:54:23.58

Code: 0xC0202009

Source: Extract AdHoc Data from Excel Excel Source [649]

Description: An OLE DB error has occurred. Error code: 0x80040E37.

End Error

Error: 2006-02-01 15:54:23.58

Code: 0xC02020E8

Source: Extract AdHoc Data from Excel Excel Source [649]

Description: Opening a rowset for "Sheet1$" failed. Check that the object exists in the database.

End Error

Error: 2006-02-01 15:54:23.58

Code: 0xC004706B

Source: Extract AdHoc Data from Excel DTS.Pipeline

Description: "component "Excel Source" (649)" failed validation and returned validation status "VS_ISBROKEN".

End Error

|||

Finally I found the problem:

The way to put the command string is not right after dtexec /SQL.

If there is not ENTER and all commands in one line (as it is a dos command), everything is OK!

Is it COOL!?

Guangming

can I send a variable table name

Hi every one,
Can i send a variable table name in to the store procedure
in ORACLE8i
eg
create procedure sample
(x as numeric, table_name as varchar(150))
is begin
if x = 1 then
select * from table_name;
end if;
end;
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
On Fri, 18 Mar 2005 00:16:06 -0800, Param N wrote:

>Hi every one,
>Can i send a variable table name in to the store procedure
>in ORACLE8i
(snip)
Hi Param8,
You'd better ask in a newsgroup for Oracle. This group is for Microsoft
SQL Server.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

can I send a variable table name

Hi every one,
Can i send a variable table name in to the store procedure
in ORACLE8i
eg
create procedure sample
(x as numeric, table_name as varchar(150))
is begin
if x = 1 then
select * from table_name;
end if;
end;
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!On Fri, 18 Mar 2005 00:16:06 -0800, Param N wrote:

>Hi every one,
>Can i send a variable table name in to the store procedure
>in ORACLE8i
(snip)
Hi Param8,
You'd better ask in a newsgroup for Oracle. This group is for Microsoft
SQL Server.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

can I send a variable table name

Hi every one,
Can i send a variable table name in to the store procedure
in ORACLE8i
eg
create procedure sample
(x as numeric, table_name as varchar(150))
is begin
if x = 1 then
select * from table_name;
end if;
end;
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!On Fri, 18 Mar 2005 00:16:06 -0800, Param N wrote:
>Hi every one,
>Can i send a variable table name in to the store procedure
>in ORACLE8i
(snip)
Hi Param8,
You'd better ask in a newsgroup for Oracle. This group is for Microsoft
SQL Server.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Thursday, February 16, 2012

Can I return a value in a variable from a SSIS program back to C# after the SSIS program is run

Can I return a value in a variable from a SSIS program back to C# after the SSIS program is run from C#?Yes - you can use the variables property of the Package object: http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.dtscontainer.variables.aspx

Can I retrieve a result set from a sp into a variable within a Execute SQL Task?

Can I retrieve a result set from a sp into a variable within a Execute SQL Task?I can't see why not... Have you tried?|||I have done it using the result set property for that. I guess you can do the same using a SP but may be you need to use the parameter tab of the Execute SQl task to set an output parameter that is mapped to the variable.|||I have tried this with just about every combination available with no luck. Do you need to add anything to the exec command? I am passing it one variable and it now looks like this "exec sp_name '20071201'" Do I need to change it to look like this? "exec sp_name '20071201', ?" or this? "exec sp_name '20071201', ? OUTPUT". I also have a variable set up under result set and included it in executevariablevalue. Just to be clear the SP is not putting anything in a variable but builds a report in a fiels and at the end does a select @.report to display what was built in @.report. I hope this is clear. Thanks.|||What *exactly* do you have entered in the SQLStatement box?|||I am building it in a variable that contains

exec sp_name '20071201'|||So just to be clear... You don't have "exec sp_name @.User::Var" listed.|||

Aha!, so the SSIS variable is to pass the SQL statement tothe Execute SQL task?

I thoght you were trying to put the output of the SP into a SSIS variable which is different.

Please clarify this....

|||

agentf1 wrote:

Can I retrieve a result set from a sp into a variable within a Execute SQL Task?

There's a downloadable demo of doing this here:

Execute SQL Task into an object variable - Shred it with a Foreach loop(http://blogs.conchango.com/jamiethomson/archive/2005/07/04/SSIS-Nugget_3A00_-Execute-SQL-Task-into-an-object-variable-_2D00_-Shred-it-with-a-Foreach-loop.aspx)

It sounds as though you're not interested in the bit about the Foreach loop but the bit about the Execute SQL Task is exactly what you after.

-Jamie

|||I am passing the sql in a variable and have a resultset set up to retreive the output/result set from the SP.|||

agentf1 wrote:

I am passing the sql in a variable and have a resultset set up to retreive the output/result set from the SP.

So where exactly is the problem?

If you need the sql statment to be dynamic; you may want to use an expression inside of the Execute SQL Task to set the SQLStatementSource property:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=662860&SiteID=1

Now the second part would be to get the SP output into a SSIS variable; for that you can follow Jamies sugestion. If the SP returns more than one row you will need a SSIS variable of Object type.

|||

agentf1 wrote:

I am passing the sql in a variable and have a resultset set up to retreive the output/result set from the SP.

You haven't told us why this doesn't work. Do you get an error? Does anything happen?

-Jamie

|||I looked at Jamies example and it is pretty much what I am doing with the exception I am trying to get a result set from a sp not a select statement.

This is the error message I am getting
.

Error: 0xC001F009 at D3OLNAC3: The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
Error: 0xC002F210 at Run sp_D3ALNAC1, Execute SQL Task: Executing the query "exec sp_D3acls1 '20061204'" failed with the following error: "The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Error: 0xC001F009 at D3OLNAC3: The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
Task failed: Run sp_D3ALNAC1
Error: 0xC0019001 at Run sp_D3ALNAC1: The wrapper was unable to set the value of the variable specified in the ExecutionValueVariable property.
Warning: 0x80019002 at D3OLNAC3: The Execution method succeeded, but the number of errors raised (7) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
SSIS package "D3OLNAC3.dtsx" finished: Failure.

I have a variable named User::spmessage defined as string. I have this in execvaluevariable on the execute sql task that runs the sp. On this task I also have a result set set up for the same variable with a result set name of 0. I also have result set type properties set up to say ResultSetType_Rowset and have also tried singlerow.

I am passing the sql to the task in a different variable and it contains
exec sp_name '20061201'

I have also tried different combination of this by adding ,? and ,? OUTPUT to the end of that exec statement.

I really appreciate all of your help and guidance.|||TTT|||Is User::spmessage a variable of the "object" data type?

Can I retrieve a result set from a sp into a variable within a Execute SQL Task?

Can I retrieve a result set from a sp into a variable within a Execute SQL Task?I can't see why not... Have you tried?|||I have done it using the result set property for that. I guess you can do the same using a SP but may be you need to use the parameter tab of the Execute SQl task to set an output parameter that is mapped to the variable.|||I have tried this with just about every combination available with no luck. Do you need to add anything to the exec command? I am passing it one variable and it now looks like this "exec sp_name '20071201'" Do I need to change it to look like this? "exec sp_name '20071201', ?" or this? "exec sp_name '20071201', ? OUTPUT". I also have a variable set up under result set and included it in executevariablevalue. Just to be clear the SP is not putting anything in a variable but builds a report in a fiels and at the end does a select @.report to display what was built in @.report. I hope this is clear. Thanks.|||What *exactly* do you have entered in the SQLStatement box?|||I am building it in a variable that contains

exec sp_name '20071201'|||So just to be clear... You don't have "exec sp_name @.User::Var" listed.|||

Aha!, so the SSIS variable is to pass the SQL statement tothe Execute SQL task?

I thoght you were trying to put the output of the SP into a SSIS variable which is different.

Please clarify this....

|||

agentf1 wrote:

Can I retrieve a result set from a sp into a variable within a Execute SQL Task?

There's a downloadable demo of doing this here:

Execute SQL Task into an object variable - Shred it with a Foreach loop(http://blogs.conchango.com/jamiethomson/archive/2005/07/04/SSIS-Nugget_3A00_-Execute-SQL-Task-into-an-object-variable-_2D00_-Shred-it-with-a-Foreach-loop.aspx)

It sounds as though you're not interested in the bit about the Foreach loop but the bit about the Execute SQL Task is exactly what you after.

-Jamie

|||I am passing the sql in a variable and have a resultset set up to retreive the output/result set from the SP.|||

agentf1 wrote:

I am passing the sql in a variable and have a resultset set up to retreive the output/result set from the SP.

So where exactly is the problem?

If you need the sql statment to be dynamic; you may want to use an expression inside of the Execute SQL Task to set the SQLStatementSource property:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=662860&SiteID=1

Now the second part would be to get the SP output into a SSIS variable; for that you can follow Jamies sugestion. If the SP returns more than one row you will need a SSIS variable of Object type.

|||

agentf1 wrote:

I am passing the sql in a variable and have a resultset set up to retreive the output/result set from the SP.

You haven't told us why this doesn't work. Do you get an error? Does anything happen?

-Jamie

|||I looked at Jamies example and it is pretty much what I am doing with the exception I am trying to get a result set from a sp not a select statement.

This is the error message I am getting
.

Error: 0xC001F009 at D3OLNAC3: The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
Error: 0xC002F210 at Run sp_D3ALNAC1, Execute SQL Task: Executing the query "exec sp_D3acls1 '20061204'" failed with the following error: "The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Error: 0xC001F009 at D3OLNAC3: The type of the value being assigned to variable "User::spmessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
Task failed: Run sp_D3ALNAC1
Error: 0xC0019001 at Run sp_D3ALNAC1: The wrapper was unable to set the value of the variable specified in the ExecutionValueVariable property.
Warning: 0x80019002 at D3OLNAC3: The Execution method succeeded, but the number of errors raised (7) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
SSIS package "D3OLNAC3.dtsx" finished: Failure.

I have a variable named User::spmessage defined as string. I have this in execvaluevariable on the execute sql task that runs the sp. On this task I also have a result set set up for the same variable with a result set name of 0. I also have result set type properties set up to say ResultSetType_Rowset and have also tried singlerow.

I am passing the sql to the task in a different variable and it contains
exec sp_name '20061201'

I have also tried different combination of this by adding ,? and ,? OUTPUT to the end of that exec statement.

I really appreciate all of your help and guidance.|||TTT|||Is User::spmessage a variable of the "object" data type?

Tuesday, February 14, 2012

Can I read what is in a SSIS variable from within a C# program that executed it?

Can I read what is in a SSIS variable from within a C# program that executed it?Sure, just check the variables collection after execution has finished.
|||

Yes, it was pretty easy. All I needed to do was this.

Variables vars = package.Variables;

int rowcount = Convert.ToInt32(vars["count"].Value);

Sunday, February 12, 2012

Can I make DTS..........

Can I make a DTS package that its destination place can be variable/input?
Because I want its DTS package can be called by each client to export
client's data. (client's data use Foxpro).
Or May I make Stored procedure to instead it? Give me solution? And give me
its listing code? or not, give me some refferences to be learned by me.Adi,
Yes it's possible. Here is the procedure
1) Create two global variables in your DTS package one each for
destination server and destination database (assuming your destination
is SQL Server) say strServer & strDB
2) Have dynamic propeties task object positioned at the begining in
your package (u need to have this before destination connection in
order) , this task can be used to assign values present in the global
variables to various DTS objects , in your case it will be destination
connection object.
Check BOL or www.sqldts.com for reference on dynamic properties task or
global variables.
3)Now, we can pass different values to these global variables during
run time using SQLAgent Job.Create separate job for each client, you
can call same DTS package thru different jobs and pass different values
for global variables.
eg:dtsrun /E /N"<packageName>" /S<Server Name> /A "<Global Variable
name eg: strServerName>":"8"="<Actual Server Name>" /A "<Global
Variable name eg: dbName>":"8"="<Actual dbName>"
check for dtsrun utility in SQL Server BOL or sqldts.com