| Author |
Topic |
|
jggtz
Starting Member
32 Posts |
Posted - 2008-06-23 : 14:46:06
|
MS SQL SERVER 2005My problem is the next :I have a Stored Procedure that execute several tasksIf I write the SP en the following format :quote: USE [REPORTES]GO/****** Object: StoredProcedure [dbo].[Astral_sp_AcCpasArtC] Script Date: 06/23/2008 11:29:16 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[Astral_sp_AcCpasArtC]ASBEGIN SELECT ... UPDATE ... INSERT ...END
It saves ok in Stored Procedures folder but doesn't run ok only send the message = Command(s) completed successfully.OtherwiseIf I write the SP in the following format :quote: USE [REPORTES]GO/****** Object: StoredProcedure [dbo].[Astral_sp_AcCpasArtC] Script Date: 06/23/2008 11:29:16 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[Astral_sp_AcCpasArtC]ASGO SELECT ...GO UPDATE ...GO INSERT ...GO
It run ok select/update/insert records but doesn't saves in Stored Procedures folderIt only save the next part :quote: USE [REPORTES]GO/****** Object: StoredProcedure [dbo].[Astral_sp_AcCpasArtC] Script Date: 06/23/2008 11:29:16 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[Astral_sp_AcCpasArtC]AS
Also, when the SP has only one task (let's say a Select), it works ok with AS BEGIN - END formatWich could be the problem?Thanks JG |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-06-23 : 14:53:20
|
| Do not put GO statements inside your stored procedure. That indicates the end of the batch, which is why you are only getting part of the code saved.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
jggtz
Starting Member
32 Posts |
Posted - 2008-06-23 : 15:00:58
|
Thank Tara, But if I write the SP en the following format :quote: USE [REPORTES]GO/****** Object: StoredProcedure [dbo].[Astral_sp_AcCpasArtC] Script Date: 06/23/2008 11:29:16 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[Astral_sp_AcCpasArtC]ASBEGIN SELECT ... UPDATE ... INSERT ...END
It saves ok in Stored Procedures folder but DOESN'T RUN ok, it doesn't select-update-insert records only send the message = "Command(s) completed successfully"ThanksJG |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-06-23 : 15:03:52
|
| That's because you haven't executed the code, all you did was "save" it.GO does not execute code either, it just indicates the end of a batch.To execute the stored procedure, do this in a new query window:EXEC Astral_sp_AcCpasArtcThen hit F5 or the green arrow to run it.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
jggtz
Starting Member
32 Posts |
Posted - 2008-06-23 : 15:18:08
|
Thanks TaraPlease be patient, I'm really new with SPOf course that I execute the SP and I mention that it saves ok to make clear that it doesn't have errorsPlease reread my post and take note that the most relevant here is that if I usequote: USE [REPORTES]GO/****** Object: StoredProcedure [dbo].[Astral_sp_AcCpasArtC] Script Date: 06/23/2008 11:29:16 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[Astral_sp_AcCpasArtC]ASBEGINSELECT ...UPDATE ...INSERT ...END
It doesn't Execute ok, it didn't select-update-insert records, only send a message that saying "Command(s) completed successfully" |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-06-23 : 15:20:42
|
| You need to read my last post again. To run the select-update-insert inside your stored procedure, you must execute it properly. You can do that with EXEC statement.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-23 : 16:13:08
|
quote: Originally posted by jggtz Thanks TaraPlease be patient, I'm really new with SPOf course that I execute the SP and I mention that it saves ok to make clear that it doesn't have errorsPlease reread my post and take note that the most relevant here is that if I usequote: USE [REPORTES]GO/****** Object: StoredProcedure [dbo].[Astral_sp_AcCpasArtC] Script Date: 06/23/2008 11:29:16 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[Astral_sp_AcCpasArtC]ASBEGINSELECT ...UPDATE ...INSERT ...END
It doesn't Execute ok, it didn't select-update-insert records, only send a message that saying "Command(s) completed successfully"
As said, you have complied the procedure. To run it useEXEC [dbo].[Astral_sp_AcCpasArtC]MadhivananFailing to plan is Planning to fail |
 |
|
|
jggtz
Starting Member
32 Posts |
Posted - 2008-06-23 : 23:28:05
|
| Tara MadhivananThank You very much for help meI learned a little moreJG |
 |
|
|
|