Hello, On Tue, May 19, 2009 at 2:23 PM, Daniel <daniel.watr...@gmail.com> wrote:
> > I have a stored procedure for SQL Server and I would like to be able > to execute the code to create the stored procedure using SA. Here's > the basic idea. > > engine = sqlalchemy.create_engine('mssql://connectionString') > engine.execute(myStoredProcedure) > > Where: > myStoredProcedure = """ > PRINT 'generate mySP stored procedure' > IF object_id('mySP') IS NOT NULL > BEGIN > DROP PROCEDURE mySP > END > GO > > CREATE PROCEDURE mySP > AS > DECLARE @aVar VARCHAR(48) > BEGIN > SELECT TOP 1 > @aVar = aVar > FROM [dbo].[someTable] (UPDLOCK) > WHERE > priority > 0 > ORDER BY > priority DESC > > SELECT > @aVar AS aVar > END > GO > """ > You will need to split this into two separate execute calls. Also this stored procedure should be simplified. There's no reason for the local variable. It can be simplified as: CREATE PROCEDURE mySP AS SELECT TOP 1 aVar FROM [dbo].[someTable] (UPDLOCK) WHERE priority > 0 ORDER BY priority DESC GO -- Michael Trier http://michaeltrier.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---