Solved

With as in a view

Posted on 2012-03-28
2
253 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 500 total points
Comment Utility
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
Comment Utility
Great thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now