Learn more about programming SSIS packages in C# .net and VB .net from the below link:
http://www.sqllion.com/2009/05/ssis-programming-basic/
Thanks,
redi31 wrote:
Exporting Stored Procedure Results w/ SSIS?
02-Dec-08
Hello,
I'm working with a stored procedure written by our software vendor and
trying to get the results of this stored procedure exported into some kind of
file so i can load it up on another server for reporting purposes.
The stored proc uses the FOR XML RAW command and I had lots of trouble
finding information on exporting XML data from SQL 2005 using SSIS. As far
as I can tell at this point SSIS can't do hardly anything I want it to
without having to sit down for 3 weeks beating my head against the wall
trying to figure out every little detail.
That I need to save for when I Have time to do nothing productive for 3
weeks...
I wanted to just execute the stored proc and jam the results into a file,
SSIS does not like that since it was outputting FOR XML RAW.
SO i re-created the SP without that parameter.
If i execute the following query, I get a result set just fine:
create table #advisortemp
(
group_id int,
group_desc nvarchar(50),
group_type nvarchar(1),
display_column nvarchar(1),
display_row int,
info_text nvarchar(100),
info_href nvarchar(100),
group_image nvarchar(max),
image_height int,
image_width int,
metric_id int,
metric_desc nvarchar(100),
sum_metric_value nvarchar(100),
metric_format nvarchar(1),
am_display_row int,
am_display_column int,
link_href nvarchar(100),
metric_type nvarchar(1),
info_href_unread_image nvarchar(25),
info_href_unread_image_height int,
info_href_unread_image_width int,
info_href_read_image int,
info_href_read_image_height int,
info_href_read_image_width int,
metric_scope nvarchar(1),
metric_type_image int,
metric_type_image_height int,
metric_type_image_width int,
metric_type_image_tooltip nvarchar(60),
range_type nvarchar(1),
metric_desc_tooltip nvarchar(60)
)
insert into #advisortemp
(
group_id,
group_desc,
group_type,
display_column,
display_row,
info_text,
info_href,
group_image,
image_height,
image_width,
metric_id,
metric_desc,
sum_metric_value,
metric_format,
am_display_row,
am_display_column,
link_href,metric_type,
info_href_unread_image,
info_href_unread_image_height,
info_href_unread_image_width,
info_href_read_image,
info_href_read_image_height,
info_href_read_image_width,
metric_scope,metric_type_image,
metric_type_image_height,
metric_type_image_width,
metric_type_image_tooltip,
range_type,
metric_desc_tooltip
)
exec dbo.sv_ng_advisor '0060', null, '2643', null
select * from #advisortemp
GO
I get this error if i plug it in as a query to specify data to transfer in
SSIS on my SQL 2005 Enterprise x64 SP2 system. I cannot go any further.
TITLE: SQL Server Import and Export Wizard
------------------------------
The statement could not be parsed.
------------------------------
ADDITIONAL INFORMATION:
Deferred prepare could not be completed.
Statement(s) could not be prepared.
Invalid object name '#advisortemp'. (Microsoft SQL Native Client)
------------------------------
BUTTONS:
OK
------------------------------
If i run this query and replace temp table w/ table variable, it allows me
to parse the statement and it also returns the result set. But running it in
SSIS, it always exports 0 rows even though everything says it runs fine...
declare @advisor TABLE
(
group_id int,
group_desc nvarchar(50),
group_type nvarchar(1),
display_column nvarchar(1),
display_row int,
info_text nvarchar(100),
info_href nvarchar(100),
group_image nvarchar(max),
image_height int,
image_width int,
metric_id int,
metric_desc nvarchar(100),
sum_metric_value nvarchar(100),
metric_format nvarchar(1),
am_display_row int,
am_display_column int,
link_href nvarchar(100),
metric_type nvarchar(1),
info_href_unread_image nvarchar(25),
info_href_unread_image_height int,
info_href_unread_image_width int,
info_href_read_image int,
info_href_read_image_height int,
info_href_read_image_width int,
metric_scope nvarchar(1),
metric_type_image int,
metric_type_image_height int,
metric_type_image_width int,
metric_type_image_tooltip nvarchar(60),
range_type nvarchar(1),
metric_desc_tooltip nvarchar(60)
)
insert into @advisor
(
group_id,
group_desc,
group_type,
display_column,
display_row,
info_text,
info_href,
group_image,
image_height,
image_width,
metric_id,
metric_desc,
sum_metric_value,
metric_format,
am_display_row,
am_display_column,
link_href,metric_type,
info_href_unread_image,
info_href_unread_image_height,
info_href_unread_image_width,
info_href_read_image,
info_href_read_image_height,
info_href_read_image_width,
metric_scope,metric_type_image,
metric_type_image_height,
metric_type_image_width,
metric_type_image_tooltip,
range_type,
metric_desc_tooltip
)
exec dbo.sv_ng_advisor '0060', null, '2643', null
select * from @advisor
GO
What am i doing wrong? Is there an easier way to export the rows returned
by the stored procedure? Why doesn't my table variable return any rows even
though it runs fine in query analyzer? Why isn't the SSIS import/export
wizard smart enough to realize i put a temp table in the query?
Is there some trick to exporting data from a stored proc that uses the FOR
XML RAW format into a flat file or whatever other file is doable?
I'm totally disappointed w/ SSIS. I don't understand why everyone says its
so much better than DTS was. I have had nothing but trouble trying even to
use the wizards from it. I never had any issues using DTS in the past on
2000.
In adddition, for having all this wonderful XML integration, SQL 2005 sure
doesn't seem to provide much for exporting out of the box. How integrated is
that?
Previous Posts In This Thread:
On Tuesday, December 02, 2008 3:21 PM
redi31 wrote:
Exporting Stored Procedure Results w/ SSIS?
Hello,
I'm working with a stored procedure written by our software vendor and
trying to get the results of this stored procedure exported into some kind of
file so i can load it up on another server for reporting purposes.
The stored proc uses the FOR XML RAW command and I had lots of trouble
finding information on exporting XML data from SQL 2005 using SSIS. As far
as I can tell at this point SSIS can't do hardly anything I want it to
without having to sit down for 3 weeks beating my head against the wall
trying to figure out every little detail.
That I need to save for when I Have time to do nothing productive for 3
weeks...
I wanted to just execute the stored proc and jam the results into a file,
SSIS does not like that since it was outputting FOR XML RAW.
SO i re-created the SP without that parameter.
If i execute the following query, I get a result set just fine:
create table #advisortemp
(
group_id int,
group_desc nvarchar(50),
group_type nvarchar(1),
display_column nvarchar(1),
display_row int,
info_text nvarchar(100),
info_href nvarchar(100),
group_image nvarchar(max),
image_height int,
image_width int,
metric_id int,
metric_desc nvarchar(100),
sum_metric_value nvarchar(100),
metric_format nvarchar(1),
am_display_row int,
am_display_column int,
link_href nvarchar(100),
metric_type nvarchar(1),
info_href_unread_image nvarchar(25),
info_href_unread_image_height int,
info_href_unread_image_width int,
info_href_read_image int,
info_href_read_image_height int,
info_href_read_image_width int,
metric_scope nvarchar(1),
metric_type_image int,
metric_type_image_height int,
metric_type_image_width int,
metric_type_image_tooltip nvarchar(60),
range_type nvarchar(1),
metric_desc_tooltip nvarchar(60)
)
insert into #advisortemp
(
group_id,
group_desc,
group_type,
display_column,
display_row,
info_text,
info_href,
group_image,
image_height,
image_width,
metric_id,
metric_desc,
sum_metric_value,
metric_format,
am_display_row,
am_display_column,
link_href,metric_type,
info_href_unread_image,
info_href_unread_image_height,
info_href_unread_image_width,
info_href_read_image,
info_href_read_image_height,
info_href_read_image_width,
metric_scope,metric_type_image,
metric_type_image_height,
metric_type_image_width,
metric_type_image_tooltip,
range_type,
metric_desc_tooltip
)
exec dbo.sv_ng_advisor '0060', null, '2643', null
select * from #advisortemp
GO
I get this error if i plug it in as a query to specify data to transfer in
SSIS on my SQL 2005 Enterprise x64 SP2 system. I cannot go any further.
TITLE: SQL Server Import and Export Wizard
------------------------------
The statement could not be parsed.
------------------------------
ADDITIONAL INFORMATION:
Deferred prepare could not be completed.
Statement(s) could not be prepared.
Invalid object name '#advisortemp'. (Microsoft SQL Native Client)
------------------------------
BUTTONS:
OK
------------------------------
If i run this query and replace temp table w/ table variable, it allows me
to parse the statement and it also returns the result set. But running it in
SSIS, it always exports 0 rows even though everything says it runs fine...
declare @advisor TABLE
(
group_id int,
group_desc nvarchar(50),
group_type nvarchar(1),
display_column nvarchar(1),
display_row int,
info_text nvarchar(100),
info_href nvarchar(100),
group_image nvarchar(max),
image_height int,
image_width int,
metric_id int,
metric_desc nvarchar(100),
sum_metric_value nvarchar(100),
metric_format nvarchar(1),
am_display_row int,
am_display_column int,
link_href nvarchar(100),
metric_type nvarchar(1),
info_href_unread_image nvarchar(25),
info_href_unread_image_height int,
info_href_unread_image_width int,
info_href_read_image int,
info_href_read_image_height int,
info_href_read_image_width int,
metric_scope nvarchar(1),
metric_type_image int,
metric_type_image_height int,
metric_type_image_width int,
metric_type_image_tooltip nvarchar(60),
range_type nvarchar(1),
metric_desc_tooltip nvarchar(60)
)
insert into @advisor
(
group_id,
group_desc,
group_type,
display_column,
display_row,
info_text,
info_href,
group_image,
image_height,
image_width,
metric_id,
metric_desc,
sum_metric_value,
metric_format,
am_display_row,
am_display_column,
link_href,metric_type,
info_href_unread_image,
info_href_unread_image_height,
info_href_unread_image_width,
info_href_read_image,
info_href_read_image_height,
info_href_read_image_width,
metric_scope,metric_type_image,
metric_type_image_height,
metric_type_image_width,
metric_type_image_tooltip,
range_type,
metric_desc_tooltip
)
exec dbo.sv_ng_advisor '0060', null, '2643', null
select * from @advisor
GO
What am i doing wrong? Is there an easier way to export the rows returned
by the stored procedure? Why doesn't my table variable return any rows even
though it runs fine in query analyzer? Why isn't the SSIS import/export
wizard smart enough to realize i put a temp table in the query?
Is there some trick to exporting data from a stored proc that uses the FOR
XML RAW format into a flat file or whatever other file is doable?
I'm totally disappointed w/ SSIS. I don't understand why everyone says its
so much better than DTS was. I have had nothing but trouble trying even to
use the wizards from it. I never had any issues using DTS in the past on
2000.
In adddition, for having all this wonderful XML integration, SQL 2005 sure
doesn't seem to provide much for exporting out of the box. How integrated is
that?
On Tuesday, December 02, 2008 3:26 PM
redi31 wrote:
I guess i had the programming group highlighted instead of integration
I guess i had the programming group highlighted instead of integration
services.
Should I re-post this there?
"redi311" wrote:
On Tuesday, December 02, 2008 3:34 PM
mouser wrote:
The issue is that because stored procedures do not store metadata in
The issue is that because stored procedures do not store metadata in the
catalog, SSIS attempts to determine the metadata via SET FMTONLY ON. The
trouble with SET FMTONLY ON is that it is extremely fragile and will break
under a number of circumstances. In your case, it is because you are using
a temp table. If you convert the temp table to a table variable (not always
good for performance), you will not have this problem but there may be other
problems that will prevent the metadata from being retrieved. In general, a
good litmus test for whether a stored procedure will work as a source for a
data flow is to execute the stored procedure in SSMS with SET FMTONLY ON.
If you do this right now, you will see that the same error will be returned
to you as SSIS.
This is a tough one to workaround because it means you have to tweak your
stored procedure to satisfy FMTONLY ON. If the stored procedure is simple
enough you could convert it to a table-valued function which SSIS has no
problem with because it stores metadata in the catalog.
mouser
On Tuesday, December 02, 2008 3:39 PM
mouser wrote:
Re: Exporting Stored Procedure Results w/ SSIS?
On 2-Dec-2008, "mouser" wrote:
By the way, I just reread your post and see that I missed the bottom half of
it. It appears you did convert to a table variable and that SSIS accepted
the stored procedure. But, you are saying it now exports 0 rows? I would
hazard a guess that the problem might not be with SSIS. I would put a data
viewer on the output of the source adapter and run it in debug mode to see
if possibly the output is being discarded later on in your data flow.
mouser
On Wednesday, December 03, 2008 4:17 AM
M wrote:
What was the error message?
What was the error message?
An alternative would be to rewrite the procedure to return the result as XML
in an output parameter. Then you could use the Execute SQL Task to invoke the
procedure, to retrieve the result and store it in a variable (by using the
ADO.Net provider instead of the OLEDB the XML data type is available in
variable/parameter mapping - just make sure you set its size to 2147483647).
You can then write the data from the variable to a file using a Script Task.
ML
---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
On Thursday, December 04, 2008 3:29 PM
redi31 wrote:
If i put exec dbo.
If i put exec dbo.ng_advisor '0060', null, '2643', null
in the query portion of the SSIS import/export wizard it tells me the SQL
statement is not a query when i try to parse it.
if i use the query i posted to create the tables for it, it exports nothing
w/ table variables, although it shows success in the little check marks page.
Using temp tables it won't parse the statement either.
Both of the queries return data straight from SSMS executing it as posted.
Exporting either yields the wizard griping about parsing or no rows. No
other errors that I can see, but I'm no expert on SSIS.
I could probably do a data reader and write to a .txt file. I thought MS
was touting how integrated the XML was in SQL 2005 and SQL 2008... It just
seems silly that there isn't a good way to caputre the output of a stored
procedure from the import/export wizard, it gripes about everything that runs
fine in management studio's query analyzer
"ML" wrote:
On Thursday, December 04, 2008 6:35 PM
mouser wrote:
On 4-Dec-2008, =?Utf-8?B?cmVkaTMxMQ==?
wrote:
Well SSIS is a useful, but imo very flawed tool for a number of reasons. I
hope they improve it in future iterations...
--
mouser
On Friday, December 05, 2008 4:35 AM
M wrote:
Import/export wizard? Why would anyone want to use that?
Import/export wizard? Why would anyone want to use that?
Have you tried rewriting your procedure the way I suggested?
ML
---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
On Friday, December 05, 2008 12:41 PM
redi31 wrote:
I re-wrote it and removed the FOR XML RAW statement.
I re-wrote it and removed the FOR XML RAW statement. I used powershell and
populated a .NET dataset object that I iterated through and wrote a text file
containing the results.
I'm going to tinker with the XML output parameter, but didn't have time to
dig really far into it at this time, since its all go go go hurry hurry hurry.
I'm glad i know enough about that stuff, as a newer (SQL 2005)DBA who
doesn't spend all day coding in XML and .NET, it would sure be nice if that
SSIS wizard made our lives easier instead of more difficult.
I guess I'll just throw SSIS out the window and do everything as a CLR
assembly or powershell script since the tools I'm provided w/ in SQL aren't
quite doing what I need.
Thank you, the advice got me going to a place I could succeed, although it
wasn't exactly what I expected.
Are there plans to make exporting stored procedure outputs and xml results
easier to those of us who aren't C# / .NET language gurus?
"ML" wrote:
Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Report Engine, Part 4
http://www.eggheadcafe.com/tutorials/aspnet/5ac799db-385f-431a-8a45-8b...b7f3186 >> Stay informed about: Exporting Stored Procedure Results w/ SSIS?