Pages

Tuesday, August 4, 2015

An interesting way of aliasing TIP#107

I recently gone through something and found a unique way of aliasing. I thought it must be share so other techies also aware of it (or might be you already aware of it).

See below example

SELECT *
FROM (VALUES ('Rajat',30),
             ('Sandeep',40),
             ('Sunil',35),
             ('Shreya',50),
             ('Virendra',45)) AS T(Name,Runs)

aliasing

Now when you it  you will get following result

Aliasing_result

I hope you may like this tips.

Enjoy!!!

RJ!!!

2 comments:

  1. Nice!

    Beats having something like

    SELECT 'Rajat' as Name, 30 as Runs
    UNION ALL
    SELECT 'Sandeep', 40
    UNION ALL
    SELECT 'Sunil', 35
    UNION ALL
    SELECT 'Shreya', 50
    UNION ALL
    SELECT 'Virendra', 45



    Available since SQL Server 2008, documentation available here:

    https://msdn.microsoft.com/en-us/library/dd776382.aspx

    ReplyDelete
  2. Well that's handy! Cheers mate.

    ReplyDelete