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

x
?
Solved

With as in a view

Posted on 2012-03-28
2
Medium Priority
?
261 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

721 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