Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query from Source not sure how to get into Destination


Query from Source not sure how to get into Destination

Author
Message
jameslauf
jameslauf
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 567
I am using SSIS 2012 and am pulling from a Server in cloud that I have read only rights to. after I finish pulling all the Table data I am trying to verify I received everything by doing Count of Rows on all tables.

Here is the Query my boss gave me to get rowcount on the read only server.

DECLARE @TableName VARCHAR(100),
@sql VARCHAR(MAX)
SET @SQL = ''

DECLARE cursorDB_Action CURSOR FAST_FORWARD FOR
SELECT Name FROM sys.objects WHERE type = 'U' and SCHEMA_ID = 1

OPEN cursorDB_Action

FETCH NEXT FROM cursorDB_Action INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQL = @SQL + '
select db_name() + '' - Cloud'' as DatabaseName, '''+ @TableName + ''' as TableName, count(*) as CountOfRows, getdate() as DateRan from ' +@TableName + '
UNION'


--EXEC SP_EXECUTESQL @sql
--set @sql = ''
FETCH NEXT FROM cursorDB_Action INTO @TableName
END

CLOSE cursorDB_Action
DEALLOCATE cursorDB_Action
SET @SQL = LEFT(@SQL,LEN(@SQL) - 7 ) -- Strip out final UNION
--PRINT @sql
EXEC (@SQL)


My Question is how do I get this result into my destination DB? This does not work as an OLE DB Source inside data flow task it gives me an error about Meta data. Can I somehow make this a "Execute SQL Task" and store output somewhere? I have only done this with one result as a Variable I am not sure how to get all 4 columns and Rows.
free_mascot
free_mascot
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2885 Visits: 2235
How about linked server?

---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8411 Visits: 19511
Don't like the cursor. Can you run something like this?

SELECT o.name,
ddps.row_count
FROM sys.indexes AS i
INNER JOIN sys.objects AS o ON i.OBJECT_ID = o.OBJECT_ID
INNER JOIN sys.dm_db_partition_stats AS ddps ON i.OBJECT_ID = ddps.OBJECT_ID
AND i.index_id = ddps.index_id
WHERE i.index_id < 2 AND o.is_ms_shipped = 0 ORDER BY o.NAME



If yes, use it as an OLEDB source in a dataflow. Then you can fire the results where you want.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search