Skip to content
Advertisement

What is this TSQL V() method/syntax/function?

I have just come across this syntax for defining an inline view…

SELECT myAlias, myAlias1 FROM ( SELECT myCol, myCol1 FROM myTable ) V( myAlias, myAlias1)

I can see what the V is doing, but what is this called and where is it documented? And why would I ever want to do this when I can just define the aliases inside the inline view?

Googling seems not to be working because V is not a word!

Advertisement

Answer

V is just another alias – it’s the alias for the whole subquery, not for an individual column.

See the derived table line from the syntax for FROM:

   | derived_table [ [ AS ] table_alias ] [ ( column_alias [ ,...n ] ) ]   

V is the table_alias.

when I can just define the aliases inside the inline view

Yes, you often can. But sometimes you’re building a complex query with lots of nesting in the individual column expressions, and it’s easier to place all of the names (the table_alias and column_aliases) that will be exposed to the remaining parts of the query in one place.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement