sql server 2008 CTE Bucket filling
Hi I found below bucket filling query from this forum, however I want to extent this from using single filler value to able to use a filler table. Please see the query with sample data, all I want to...
View ArticleRecursive CTE over partitions.Detail in code.
Hi, I have a recursive CTE problem (detailed fully in the code below with source and expected results tables). Essentially, i am trying to apply a formula over partitions that includes using a constant...
View ArticleAdding Dates to Recursive CTE
I have a recursive CTE that calculates projected profit for the duration of a project. I'm trying to figure out to add a corresponding month/date to each iteration/period. My CTE is as follows. No...
View ArticleMarking Parent record in Table
Hello, I have a table that I need to replace the blank rows with the ID above. My table looks like this image. ![alt text][1] I need it to look like this. ![alt text][2] Here is the table data. Thanks!...
View ArticleSQL Link Consolidated Table back to Base Table Line Data
Hi, Note: This is related to SAP tables JDT1 and PCH1(Service or Item document) I have a Table A(JDT1) that is consolidated (based on Transid, Account and Project) from Table B(PCH1 - Line Details),...
View ArticleParent Child
I have a table that has a parentid and a childid (coa_cnf_account). I have another table that has the money associated with each of these accounts(rr_data_revenue). I am trying to get the parent total...
View ArticleJoin CTE temp table to derived table
How can I join my CTE table from a derived table? as I am getting an "Incorrect Syntax error near )" Error in join expression, unable to parse query (SELECT TOP (100) PERCENT ItemSpecs_1.ItemID,...
View Articleusing results of cte (common table expression) in a query
DECLARE @year date = dateadd(year, datediff(year, 0, '2017-01-01'), 1); WITH weeks(WeekNumber) AS ( SELECT 0 UNION ALL SELECT WeekNumber + 1 FROM weeks WHERE WeekNumber < 51 ) SELECT dateadd(week,...
View ArticleUSE CTE slow in view than use temp table in sp
I have question for SQL professional for help. I have a piece query run slow in a view(25s), I use temp table can improve the performance to 2s. Since temp table cannot use in view, I try to use CTE....
View ArticleUnion CTE's with different # of Columns
I'm trying to do a union of two CTE's. The first CTE has 7 columns and the other one has only 6 columns. I tried to pad it, but I invalid column name and not a defined system type.This is what I did...
View ArticleRemoving duplicate entries query not working
table.jpgIn the attached table, I'm trying to identify and delete the duplicate records which have 0 rates.E.G. line #2 and line #5. I want to keep the records with rates as 0 that do not have...
View ArticleCTE Duplicate record when join
HelloI have the listed CTE for earning and deduction and I the result in column so I can build the report in report builder. However I am getting duplicate with either join ; With cte_earnings (Fund...
View ArticleRecursive CTE
tables-script.txtquery.txtIf i execute the above query getting error message Transaction log for TempDB is full.Is there any way to write recursive CTE for above query to improve the performance?
View ArticleHow to replace a SQL Server Cursor with recursive CTE ?
Using the example I need to calculate a value in r1 pass the value to r2, recalculate from the passed value maintaining the passed value and then pass the new value to r3. Noting that the aggregation...
View ArticleI want to replace cursor in from the bellow query
USE [AxisDataWarehouse_UAT]GO/****** Object: StoredProcedure [dbo].[msp_GenerateClaimMovementsPCC] Script Date: 1/11/2021 5:20:06 AM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER...
View Article