Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Create View from Complex SQL query

Posted on 2006-11-10
Medium Priority
Last Modified: 2012-06-27
I have a complex sql query that I'd like to create a view for.  I went to views, create view and copied the query into it.  But it won't let me pass the @variable that I need there.  How do I do this?  Basically, whenever I use the view, I would have that parameter being passed in.

Question by:YLaw
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Accepted Solution

regbes earned 2000 total points
ID: 17916980
Hi YLaw,

you will need to create a stored procedue or a tabled valued function as views do not support parameters


Author Comment

ID: 17916985
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17916988
>  How do I do this?
Views are nothing but virtual tables, you can't pass variables. You can either go for a function or a stored procedure
LVL 29

Expert Comment

ID: 17917001
create procedure owner.spname
@variable datatype
paste here

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question