Showing posts with label thestored. Show all posts
Showing posts with label thestored. Show all posts

Tuesday, March 20, 2012

Alter Table in Stored Procedure

Hi,
The script in the stored procedure below works. But, when creating the
stored procedure, I only see the first 'if'. There is nothing in there.
I tried through Enterprise Manager as well. Anybody knows what could be
causing this?
Thanks,
CREATE PROCEDURE sp_ImportKEYBANKAccountsFeed
AS
-- Drop Constraints
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_tblAccounts_tblAccountTypes]')
and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblAccounts] DROP CONSTRAINT
[FK_tblAccounts_tblAccountTypes]
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo]. [FK_tblAccTransactions_tblTransactionTyp
es]')
and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblAccTransactions] DROP CONSTRAINT
[FK_tblAccTransactions_tblTransactionTyp
es]
GO
-- Clean tables
TRUNCATE TABLE [dbo].[tblAccounts]
GO
TRUNCATE TABLE [dbo].[tblAccountTypes]
GO
TRUNCATE TABLE [dbo].[tblAccTransactions]
GO
TRUNCATE TABLE [dbo].[tblTransactionTypes]
GO
-- Populate tables
INSERT INTO tblAccountTypes
(
AccountTypeID,
TypeDesc
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractAccountTypes
GO
INSERT INTO tblTransactionTypes
(
TransactionTypeID,
TransactionDesc
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractTranCodes
GO
INSERT INTO tblAccounts
(
KeyBankAccID,
KeyBankCustomerID,
CACNO,
AccountTypeID,
Balance,
InterestRate,
DateOpened,
MaturityDate,
MonthlyDepositAmt,
DateDeposit,
Settlement,
FinalPaymentDate,
DateMonthlyPmtDue,
DirectDebitDetails,
ArrearsAmt,
ProductDescription,
LedgerCd
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractESBAccounts
GO
INSERT INTO tblAccounts
(
KeyBankAccID,
KeyBankCustomerID,
CACNO,
AccountTypeID,
Balance,
InterestRate,
DateOpened,
MaturityDate,
MonthlyDepositAmt,
DateDeposit,
Settlement,
FinalPaymentDate,
DateMonthlyPmtDue,
DirectDebitDetails,
ArrearsAmt,
ProductDescription,
LedgerCd
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractSavingsAccounts
GO
INSERT INTO tblAccounts
(
KeyBankAccID,
KeyBankCustomerID,
CACNO,
AccountTypeID,
Balance,
InterestRate,
DateOpened,
MaturityDate,
MonthlyDepositAmt,
DateDeposit,
Settlement,
FinalPaymentDate,
DateMonthlyPmtDue,
DirectDebitDetails,
ArrearsAmt,
ProductDescription,
LedgerCd
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractPLAccounts
GO
INSERT INTO tblAccTransactions
(
KeyBankTransID,
KeyBankCustomerID,
AccountID,
TransactionTypeID,
Reference,
Debit,
Credit,
Balance,
Arrears,
BookingDate,
Amount,
Narrative
)
EXEC [BOSID042].[BOSI_DEV].[dbo].retExtractTrans
GO
--Add Constraints back to tables
if not exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[FK_tblAccounts_tblAccountTypes]') and
OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblAccounts] ADD CONSTRAINT
[FK_tblAccounts_tblAccountTypes]
FOREIGN KEY ([AccountTypeID]) REFERENCES [tblAccountTypes]
([AccountTypeID])
GO
if not exists (select * from dbo.sysobjects where id =
object_id(N'[dbo]. [FK_tblAccTransactions_tblTransactionTyp
es]')
and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblAccTransactions] ADD CONSTRAINT
[FK_tblAccTransactions_tblTransactionTyp
es]
FOREIGN KEY([TransactionTypeID] ) REFERENCES [tblTransactionTypes]
([TransactionTypeID])
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
*** Sent via Developersdex http://www.examnotes.net ***That's because GO is a batch terminator
If you do sp_helptext 'ImportKEYBANKAccountsFeed ' you will see that
the procedure stops after the first GO
Take out the GO's
Denis the SQL Menace
http://sqlservercode.blogspot.com/

Sunday, February 12, 2012

All procedure in a stored procedure not being exec

I have a stored procedure that is called but it seems that not all the
Stored procedures are run. If I execute it the second time then they seem to
run after that.
Am I missing something, Like added a wait to finish clause?
Stephen K. Miyasato
MDsync
CREATE PROCEDURE FLG_UpdateFlags
/*Stored Procedure to update All the Flags*/
@.PatNo int
AS
--Put optional Flag procedures here
--
--Procedure to delete FOBT if Colonoscopy duedate is > todays or to be done
Exec FLG_FOBT @.PatNo
--procedure to delete old flags Set LastDate to Visit date in Vistal Signs
Exec FLG_OfficeVisit @.PatNo
-- Update Labs based on sort and ProtScr
Exec FLG_LabDateCholesterol @.PatNoStephen K. Miyasato (miyasat@.flex.com) writes:
> I have a stored procedure that is called but it seems that not all the
> Stored procedures are run. If I execute it the second time then they
> seem to run after that.
How do you conclude this? From where do you run the procedure? Have you
traced the procedure in Profiler to see what is going on?
The only thing I can guess on is that first time you run the procedure,
there is an error that causes the batch to be aborted, but this does
for some reason not happen when you re-run the procedure.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx