Randy Hall
Randy Hall

Reputation: 8157

Parameters with or without 'AS' keyword in TSQL

I'm somewhat new to TSQL (mostly MySQL experience). I came across some parameter declarations and I'm unsure what, if any, the difference is when declared in a stored proc with versus without the 'as' keyword:

CREATE PROCEDURE [dbo].[SomeStoredProc]
    @variable1 varchar(50),
    @variable2 as varchar(50)
...

Upvotes: 5

Views: 70

Answers (3)

Rich Benner
Rich Benner

Reputation: 8113

If you're seeing variables like this and the code doesn't DECLARE them it means that these must be passed through when you execute the query;

CREATE PROCEDURE [dbo].[SomeStoredProc]
@variable1 varchar(50),
@variable2 as varchar(50)

AS


DECLARE @Variable3 varchar(50)
/* PUT YOUR STORED PROC CODE HERE */

When you run the EXEC SomeStoredProc you will need to follow that up with the values for Variable1 and Variable2 otherwise it's going to error out. Variable3 above is created within the stored proc so doesn't need to be passed through with the EXEC command.

Upvotes: 0

sagi
sagi

Reputation: 40481

As far as I'm aware of, except from aliasing columns , which AS is expected(but not mandatory) , AS is optional and more commonly not used in queries . Regarding the functionality , they are the same .

FROM Table1 AS t
FROM Table1 t 
--They are the same.

Upvotes: 1

Radu Gheorghiu
Radu Gheorghiu

Reputation: 20499

Strangely enough the documentation does not show AS as being part of the syntax neither optional nor mandatory.

But, anyway, there is no difference.

Upvotes: 2

Related Questions