[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

Error in creating stored procedure in SQL.

Everytime I run the sql code to create a procedure:

CREATE PROCEDURE dbo.CreateOpeningTrialBalance

AS

BEGIN
INSERT INTO Trial_Balance
                         (Accounting_Period, Account_Number, Account_Description, Balance)
SELECT        Date_Created, Account_Number, Account_Description, 0 AS Balance
FROM            Chart_of_Accounts
END

I get this error:

'CRATE/ALTER PROCEDURE' must be the first statement in a query batch.

What's wrong with my syntax?
 
0
WhyDidntItWork
Asked:
WhyDidntItWork
1 Solution
 
Ephraim WangoyaCommented:
Seems you have other statements before the create procedure code.

Otherwise the sql to create the SP is fine and should work with no problem
0
 
sachitjainCommented:
just put a GO before Create statement and try
0
 
viralypatelCommented:
run this :

GO

CREATE PROCEDURE dbo.CreateOpeningTrialBalance

AS

BEGIN
INSERT INTO Trial_Balance
                         (Accounting_Period, Account_Number, Account_Description, Balance)
SELECT        Date_Created, Account_Number, Account_Description, 0 AS Balance
FROM            Chart_of_Accounts
END

Open in new window

0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
Pratima PharandeCommented:
try this

IF EXISTS (SELECT name
FROM sysobjects
WHERE name = N'CreateOpeningTrialBalance
'
AND type = 'P')

DROP PROCEDURE CreateOpeningTrialBalance

GO

CREATE PROCEDURE CreateOpeningTrialBalance

AS

BEGIN
INSERT INTO Trial_Balance
                         (Accounting_Period, Account_Number, Account_Description, Balance)
SELECT        Date_Created, Account_Number, Account_Description, 0 AS Balance
FROM            Chart_of_Accounts
END

refer
http://forums.asp.net/t/1094501.aspx/1
0
 
Anthony PerkinsCommented:
>>What's wrong with my syntax?<<
Nothing, you just failed to include all the relevant code.
0
 
WhyDidntItWorkAuthor Commented:
That worked. Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now