http://www.sqlservercentral.com/blogs/steve_jones/2008/05/09/a-view-variable/

Printed 2014/08/29 08:31AM

A View Variable

By Steve Jones, 2008/05/09

 I saw that Erland Sommerskag posted a Connect item that asked for a "View Variable" to be added to the SQL language. The idea is that you would be able to declare a variable that was a query of some sort and then use that in places where you might otherwise need the query code.  Such as this:

delcare @v as (select orderid, customername from orders o inner join customers c on o.customerid  = c.customerid)

if exists ( select * from @v)

  select * from @v

It's an interesting idea, but I'm not really sure how this is better than Table variables, or maybe those need to be enhanced. It would definitely be handy to be able to use a table in some places to keep your code clean and I'm sure people would come up with some very interesting ideas for creative coding.

If you agree or disagree, rate this on Connect (1 for "don't do this" and 5 for "it needs to be done")

     


Copyright © 2002-2014 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use. Report Abuse.