SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

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


The Voice of the DBA

Steve Jones is the editor of SQLServerCentral.com and visits a wide variety of data related topics in his daily editorial. Steve has spent years working as a DBA and general purpose Windows administrator, primarily working with SQL Server since it was ported from Sybase in 1990. You can follow Steve on Twitter at twitter.com/way0utwest


No comments.

Leave a Comment

Please register or log in to leave a comment.