Top "Common-table-expression" questions

A Common Table Expression (CTE) is a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement.

Use one CTE many times

I have this, and i get an error at set total. Why can't i access a cte many times? ALTER …

sql sql-server sql-server-2008 common-table-expression
How do you UNION with multiple CTEs?

How do you use UNION with multiple Common Table Expressions? I'm trying to put together some summary numbers but no …

sql-server union common-table-expression
CTE error: "Types don't match between the anchor and the recursive part"

I am executing the following statement: ;WITH cte AS ( SELECT 1 as rn, 'name1' as nm UNION ALL SELECT rn + 1, …

sql sql-server tsql common-table-expression
Incorrect syntax near the keyword 'with'...previous statement must be terminated with a semicolon

Im using SQL Server 2005 . I have 2 WITH Clauses in my stored procedure WITH SomeClause1 AS ( SELECT .... ) WITH SomeClause2 AS ( SELECT .... ) …

sql sql-server sql-server-2005 tsql common-table-expression
SQL Server - using the WITH clause in an INSERT statement

I was wondering if this was possible. I have an existing query that uses the WITH clause to apply some …

sql sql-server common-table-expression with-clause
How to use a CTE statement in a table-valued function in SQL Server

I have come to understand that some versions of Microsoft OLE DB Provider for SQL Server (mostly on Windows XP) …

sql-server sql-server-2008-r2 common-table-expression
How can I have multiple common table expressions in a single SELECT statement?

I am in the process of simplifying a complicated select statement, so thought I would use common table expressions. Declaring …

sql sql-server sql-server-2008 tsql common-table-expression
What are the Main difference between CTE's and TEMP tables?

Is there a benefit to using CTE's (common table expressions) instead of using temp tables. I went through performance testing …

sql tsql sql-server-2008-r2 common-table-expression temp-tables
Oracle create table using with clause

Can I create a table from a query formed using with clause?

sql oracle common-table-expression
Adding an INDEX to a CTE

Should be a pretty straight forward question. Can I add an INDEX to a Common Table Expression (CTE)?

sql-server-2008 common-table-expression