Blog Post

A View Variable

,

 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")

     

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating