About 52,600 results
Open links in new tab
  1. sql - When to use Common Table Expression (CTE) - Stack Overflow

    Jan 5, 2017 · There are two reasons I see to use cte's. To use a calculated value in the where clause. This seems a little cleaner to me than a derived table. Suppose there are two tables - …

  2. Keeping it simple and how to do multiple CTE in a query

    Example C, "Using multiple CTE definitions in a single query," calls this out explicitly. Sadly, this example is not provided in the documentation for SQL 2008 and older (i.e., the example wasn't …

  3. sql - Update records in table from CTE - Stack Overflow

    Correct, except for the fact that he summarizes his question in the title: "Update records in table from CTE". As evidence I'm reading the OP's desire for an answer that involves a CTE, I …

  4. t sql - Combining INSERT INTO and WITH/CTE - Stack Overflow

    On the other hand, if you need to use the result of the CTE in several different queries, and speed is already an issue, I'd go for a table (either regular, or temp). WITH …

  5. sql - Use one CTE many times - Stack Overflow

    Apr 17, 2012 · A CTE is, per definition, only valid for one statement. You can create an inline table-valued function and then use this as often as you like. The inline function does what the …

  6. sql - CTE within a CTE - Stack Overflow

    You can't nest CTEs like that in SQL Server but you can use multiple CTEs the following way:;with test as ( select SRnum, gamenumber, StartOfDistribution, ApplicationNumber from …

  7. MS SQL Server - How to create a view from a CTE?

    with cte as ( select '2014-03-10 08:00:00' as Dates union all select '2014-05-11 14:00:00' ) select * from cte join someTable on 1=1 OPTION (MAXRECURSION 0) The here above SQL is …

  8. CTE inside CTE in SQL Server - Stack Overflow

    Apr 10, 2014 · WITH CTE AS ( SELECT * FROM OPENQUERY([Your Server], 'Query Provide by Other System') ) SELECT * FROM CTE; You may need to configure your server for data …

  9. Declaring variable in WITH expression (SQL Server)?

    WITH CTE_Name (somevar1, somevar2) AS (SELECT 0.15, 0.65) SELECT sq.Col1 * cte.somevar1 AS Calc1, sq.Col2 * cte.somevar2 AS Calc2 FROM ( SELECT 10 Col1, 20 Col2 …

  10. sql - What are the advantages/disadvantages of using a CTE?

    Aug 4, 2016 · The following points are good reasons to use a CTE: A CTE can help you to avoid repeated sub queries. A CTE can be used multiple times within your statement, e.g. within a …

Refresh