Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

With as in a view

Posted on 2012-03-28
2
Medium Priority
?
264 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
2 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

824 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