Create View from Complex SQL query

Posted on 2006-11-10
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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

630 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