SQL SERVER – 2008 – Inline Variable Assignment

I loved this feature. I have always wanted this feature to be present in SQL Server. Last time when I met developers from Microsoft SQL Server, I had talked about this feature. I think this feature saves some time but make the code more readable.

---- SQL Server 2005 Way
@MyVar = 5
SELECT @MyVar AS TestVar
---- SQL Server 2008 Way
SELECT @MyVar AS TestVar

inlinevar SQL SERVER   2008   Inline Variable Assignment

Reference : Pinal Dave (http://blog.SQLAuthority.com)

4 thoughts on “SQL SERVER – 2008 – Inline Variable Assignment

  1. Please, help me in the following.

    Say, I have 2 Sql Server databases and I sometimes need to pull data from both of them.

    SELECT a.* FROM LocalTable a
    \\ip address\servername\dbname.remote_table b ON a.primarykey=b.somekey

    Is there any way to fill the lengthy name of my remote server into a variable and use @var.remote_table in the code shown above? It often creates problem if ip address or servername changes and also makes the code look nasty.

    Please help me to get rid of this problem out.


  2. Pingback: SQL SERVER – Weekly Series – Memory Lane – #033 | Journey to SQL Authority with Pinal Dave

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s