Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 DECLARE AS - what is the as for

Author  Topic 

asafg
Starting Member

39 Posts

Posted - 2008-09-24 : 03:54:27
This is the first time I'm working with TSQL therefor my question is very basic

I saw that there are two types of syntax to declare a local variable:
1. With AS
2. Without AS

Both work! Is there any difference of performence or something else between the two?

DECLARE @TestNow AS DATETIME
set @TestNow=getdate()
print @TestNow

and

DECLARE @TestNow DATETIME
set @TestNow=getdate()
print @TestNow

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-24 : 03:56:33
quote:
Originally posted by asafg

This is the first time I'm working with TSQL therefor my question is very basic

I saw that there are two types of syntax to declare a local variable:
1. With AS
2. Without AS

Both work! Is there any difference of performence or something else between the two?

DECLARE @TestNow AS DATETIME
set @TestNow=getdate()
print @TestNow

and

DECLARE @TestNow DATETIME
set @TestNow=getdate()
print @TestNow



both the statement batches are same. AS is just an optional keyword which can be used with DECLARE to specify datatype. Even if you not use it its not a problem.
Go to Top of Page

asafg
Starting Member

39 Posts

Posted - 2008-09-24 : 06:44:38
First, thank you.

I saw there is no visible difference, I just wanted to be sure

Thanks
Asaf
Go to Top of Page
   

- Advertisement -