Parameters with or without the keyword "AS" in TSQL

I'm a little new to TSQL (mostly MySQL experience). I came across some parameter declarations, and I'm not sure if there are any, the difference is in the declaration in the stored procedure against and without the keyword โ€œhowโ€:

CREATE PROCEDURE [dbo].[SomeStoredProc] @variable1 varchar(50), @variable2 as varchar(50) ... 
+5
source share
3 answers

Oddly enough, the documentation does not show AS as part of a syntax that is not optional and required.

But, in any case, there is no difference.

+2
source

As far as I know, in addition to the smoothing columns that AS are expected (but not required), AS is optional and is most often not used in queries. As for functionality, they are the same.

 FROM Table1 AS t FROM Table1 t --They are the same. 
+1
source

If you see such variables, and the code is not DECLARE , this means that they must be passed when the query is executed;

 CREATE PROCEDURE [dbo].[SomeStoredProc] @variable1 varchar(50), @variable2 as varchar(50) AS DECLARE @Variable3 varchar(50) /* PUT YOUR STORED PROC CODE HERE */ 

When you start EXEC SomeStoredProc , you will need to keep track of this value with the values Variable1 and Variable2 , otherwise it will result in an error. Variable3 above is created inside a stored proc, so it does not need to be passed using the EXEC command.

0
source

Source: https://habr.com/ru/post/1260087/


All Articles