Solved

With as in a view

Posted on 2012-03-28
2
257 Views
Last Modified: 2012-03-28
I am able to use one with as in  a view in sql server 2008 but get an error if I try to use more than one

is there a way to use more than one?
0
Comment
Question by:johnnyg123
[X]
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
2 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 500 total points
ID: 37777757
Separate them with commas, not new WITH statements.

CREATE VIEW V1 AS 
WITH ct1 AS (SELECT * FROM myTable WHERE ID = 2),
ct2 AS (SELECT * FROM MyTable where ID = 3)
SELECT * FROM ct2 INNER JOIN Ct2 ON ct1.Name = Ct2.Name

Open in new window

0
 

Author Closing Comment

by:johnnyg123
ID: 37778157
Great thanks!
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

697 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