question

murugansilvers avatar image
murugansilvers asked

my question is why do i use AS after tell a column name here below?

select DATEDIFF(HH,startdate,enddate)AS hourss
datediff
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JohnM avatar image
JohnM answered
There are a number of ways to alias a column in a query. Using "AS" is just one method. For example: SELECT GETDATE() 'Today' SELECT GETDATE() [Today] SELECT GETDATE() AS 'Today' SELECT 'Today' = GETDATE() All of these queries work yet just different methods to alias the column. Aaron Bertrand put out a post about this a couple of years ago: http://sqlblog.com/blogs/aaron_bertrand/archive/2012/01/23/bad-habits-to-kick-using-as-instead-of-for-column-aliases.aspx Hope that helps!
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.