In below recursive CTE script, the first statement how many times will run??
with cte(asd,length1) as ( select asd=CAST('ABC'AS VARCHAR(300)), LEN('ABCadsfasdf') --/How many times this statement will run??/ union all select CAST(asd+'ZYXWVU'AS VARCHAR(300)) , LEN(asd) from cte...
View ArticleHow to Use variable to name several database schema and table them put output...
I’m attempting to pull data out of several databases which are identical for the most part except for the db names. The following script works except for the output is in 12 separate results. Caveat is...
View ArticleCTE for directories
Hi, I need to get a summary of all files and their cumulative size per directory, as well as the total of all subdirectories in the parent, until I reach the root. I bump into several hurdles. 1) Not...
View ArticleT-SQL get record from the last value of a column
Hi, sample table TID HistoryID Action Date desc === ========= ====== ========= ==== 1 1 A 1/11/2013 abc 1 2 B 2/11/2013 xyz 2 1 A 2/11/2013 abc 2 2 C 3/11/2013 xyz 3 1 A 4/11/2013 abc 3 2 B 5/11/2013...
View ArticleNested loops in query execution plan
when I generate the execution plan for the query which is similar to the below one, I see that 97% of the query cost is for Nested Loop (Left semi Join) ![alt text][1] How can I optimize this query to...
View ArticleT-SQL MAXRECURSION with INSERT Statement Error
Thank you for looking at this. I have two CTE tables that generate duty times, the calculations are convoluted so wont bother you with them. Here is the SQL (Simplified) DECLARE @StartDate Datetime --...
View ArticleLoan EMI Mortgage Calculation
dear Geeks good day to you !!! I am stuck in a very huge problem while creating a calculator of Loan in which Mortgage will be added on daily basis. there are inputs as below...
View ArticleHow do I sequence number a recursive CTE top to bottom?
I have a recursive cte which I need to turn in to a flat file recordset AND MAINTAIN THE ORDER TOP TO BOTTOM AND KEEP TRACK OF WHICH ITEMS REPORT TO EACH LEVLEL BY THE ORDER NUMBER. Data Item Parent A...
View ArticleSumming Counts from Multiple Tables
--Supplier Count SELECT id, COUNT (*) AS cnt FROM atable WHERE id IN ('1','2',3') GROUP BY id ORDER BY id --id Count SELECT id, COUNT (*) AS cnt FROM btable WHERE id IN ('1','2',3') GROUP BY id ORDER...
View ArticleHow to use Recursion or Tally table on this problem
My problem here is how to identify and select a patients service date. A service date could be admission date(hospital), discharge date(hospital), CBC taken date, CBC result date, xray taken date, xray...
View ArticleHow to get the Name of the Purchasing.Vendor to display along with the Name...
The picture attached is the result of my class study Lab. At the moment, I am trying to get the Name of 2 different tables to not cancel out all the information for the results. The Question that I...
View ArticleGlobal CTE
I need to use the same cte for two sets of select statement next next .how to use that CREATE PROCEDURE [dbo].[sGetPlatformErrorList] @userTransId int, @vendorKey int AS BEGIN --MF 9 CHANGES START WITH...
View ArticleRecursive Query Optimization
Hi, I had a table called Person with the columnname (person_id, person_name,person_permenant_address). I need to create a model . so to reduce my effort i planned to create a query which returns an...
View ArticleCte to count then update table
I have three tables items, orders and customers. The items table have product category fields (5 different products) and the orders table have order number sand order dates. If a customer orders five...
View ArticleLIKE, IN, and a Subquery in a Single SQL Statement
Hello everyone, I am writing a query in which I am trying to search a subquery/CTE for a wildcard substring, and nesting this logic in my CASE statement. For example: SELECT CASE WHEN '%' + text + '%'...
View ArticleIn below recursive CTE script, the first statement how many times will run??
with cte(asd,length1) as ( select asd=CAST('ABC'AS VARCHAR(300)), LEN('ABCadsfasdf') --/How many times this statement will run??/ union all select CAST(asd+'ZYXWVU'AS VARCHAR(300)) , LEN(asd) from cte...
View ArticleHow to Use variable to name several database schema and table them put output...
I’m attempting to pull data out of several databases which are identical for the most part except for the db names. The following script works except for the output is in 12 separate results. Caveat is...
View ArticleCTE for directories
Hi, I need to get a summary of all files and their cumulative size per directory, as well as the total of all subdirectories in the parent, until I reach the root. I bump into several hurdles. 1) Not...
View ArticleT-SQL get record from the last value of a column
Hi, sample table TID HistoryID Action Date desc === ========= ====== ========= ==== 1 1 A 1/11/2013 abc 1 2 B 2/11/2013 xyz 2 1 A 2/11/2013 abc 2 2 C 3/11/2013 xyz 3 1 A 4/11/2013 abc 3 2 B 5/11/2013...
View ArticleNested loops in query execution plan
when I generate the execution plan for the query which is similar to the below one, I see that 97% of the query cost is for Nested Loop (Left semi Join) ![alt text][1] How can I optimize this query to...
View Article