Showing posts with label complex. Show all posts
Showing posts with label complex. Show all posts

Sunday, March 25, 2012

Can I fill a cursor from a strored procedure?

Basically, I have a complex stored procedure that combines two tables and fills a cursor.

I would like to fill another cursor in another stored procedure from the results of this first stored proc, rather than have to type it all in again.

The reason being that I am doing a one time import of some data from two tables into one new table based on some complex linking/querying.

Can I fill a cursor from the output of another stored procedure rather than an inline SELECT statement?

Does the sp I am using have to have cursor as an out parameter?a more easier way would be to create a table with all the columns tht your first cursor returns...so when you combine the 2 tables and fill the cursor...insert those records into the table..now you have a table with the records...so you can use a select statement on the table itself in the second stored proc...

HTH|||I would rather use the table option. But since the tables are shared between stored procedures then you need to use the local temp table or global temp tables.

But there are options to pass a cursor back to the calling procedure ... You would need to use an output cursor parameter in your stored procedure. Note that cursor parameters can be only output & use the keyword VARYING since the resultset supported is created dynamically by the stored procedure and whose contents can vary. Something along the lines of

CREATE PROCEDURE usp_cursor
@.orders_cursor CURSOR VARYING OUTPUT
AS
SET @.orders_cursor = CURSOR FOR
SELECT *
FROM Northwind..Orders
WHERE Freight > 100.00
OPEN @.titles_cursor
GO

You can now execute this stored procedure in a batch which declares a local cursor and assign the output cursor parameter value to the local cursor variable like :

DECLARE @.local_crsr CURSOR
EXEC usp_cursor @.orders_cursor = @.local_crsr OUTPUT
WHILE @.@.FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM @.local_crsr
...
END
CLOSE @.local_crsr
DEALLOCATE @.local_crsr|||hi
i dont have any idea about the topic cursor,can you give me a certain link that it can help me to understand very well this topic and thank you for your help|||Article on cursorssql

Thursday, February 16, 2012

Can a DTS package be scripted or transferred to another server?

I have production SQL Server database that must be moved to a new
machine. There is a fairly complex DTS package on the original server
that is used to handle the weekly updates to the database.

Is there a way to export this DTS package in order to set it up on the
new machine as well?

Best Regards,

Warren Wright
Scorex Development Teamwarren.wright@.us.scorex.com (Warren Wright) wrote in message news:<8497c269.0307291200.68fe227b@.posting.google.com>...
> I have production SQL Server database that must be moved to a new
> machine. There is a fairly complex DTS package on the original server
> that is used to handle the weekly updates to the database.
> Is there a way to export this DTS package in order to set it up on the
> new machine as well?
> Best Regards,
> Warren Wright
> Scorex Development Team

http://www.sqldts.com/default.aspx?6,105,204,0,1

The June issue of SQL Server magazine (http://www.sqlmag.com) had a
good article on making DTS packages portable between servers.

Simon|||warren.wright@.us.scorex.com (Warren Wright) wrote in message news:<8497c269.0307291200.68fe227b@.posting.google.com>...
> I have production SQL Server database that must be moved to a new
> machine. There is a fairly complex DTS package on the original server
> that is used to handle the weekly updates to the database.
> Is there a way to export this DTS package in order to set it up on the
> new machine as well?
> Best Regards,
> Warren Wright
> Scorex Development Team

You can, when designing the DTS Package, select "Save As..." and
change the "location" to a structured storage file. You can then
import this file onto your production server. If you scripted all
your local connections as "(local)", then this should be the end of
the story, if not, you'll need to open it and change your local
connections to the production server.

Hope this helps

Hodge|||Warren

Try this link.

http://www.sqldts.com/default.aspx?6,105,204,0,1

Hope that helps

John

Friday, February 10, 2012

Calling VBA functions from SQL

I have a rather complex function (part of a production planning engine) that is written in VBA, and is part of my front end app. I'd like to be able to somehow call this function from either a sproc or DTS package in SQL. Is this possible, or am I going to have to convert the function to a SQL sproc (ugh)?Plop the VBA script into an Active-X task within a DTS package, and you should be "good to go". Another choice that folks often overlook is to make the VBA an ActiveX Script step in a SQL Agent job.

-PatP|||Thanks, Pat.

I was thinking along those lines, so I did a little more research while waiting for an answer. It appears that VBScript (and ActiveX??) doesn't like arrays, especially the dynamic variety. I think what I'm trying to do may be misuse of a sproc, but since I want the task to run as part of a rather large string of scheduled tasks, I'm stuck with converting it.