SQL80001: Incorrect Syntax:" Create Procedure" must be the only statement in the batch When I try to create a procedure, I get an error message:


  SQL80001: Incorrect Syntax:" Create Procedure" must be the only statement in the batch


This is my procedure:

CREATE PROCEDURE [dbo].[USP_UserRoles_Select]
(
    @Rolename VARCHAR(30) = ''
)
AS
BEGIN
    Select ID,Name
    FROM
        AspNetRoles
    WHERE
        Name like  @Rolename +'%'
END


What does the error mean and how to fix it?
You just need to put a GO batch separator around your CREATE PROCEDURE. You have something else above it, and it needs to be in its own batch. Hence the GO that's needed.

GO
CREATE PROCEDURE [dbo].[USP_UserRoles_Select]
(
    @Rolename VARCHAR(30) = ''
)
AS
BEGIN
    Select ID,Name
    FROM
        AspNetRoles
    WHERE
        Name like  @Rolename +'%'
END
GO


A GO is also needed after the script if there is code following the END. The BEGIN and END statements are superfluous so all code in the batch will be part of the stored procedure.