Skip to content
Advertisement

Tag: tsql

Recursive query compute parent values

I have 2 tables Persons and Sales. In Person there is relation between child and parent, I want to compute 20 percent of parent values with the following condition Persons Sales I want to get result like this I wrote this query but it does not give appropriate result Answer This should be a two steps algorithm. First traverse the

Recursively Conditionally get parent Id

I have two tables: Budget Line and Expense. They are structured in such a way that an expense must have either a parent record in the budget line table, or a parent record in the expense table. I need to select all child-most expenses for each budget line. For example – BudgetLine: Id Description 1 TEST123 2 OTHERTEST Expense: Id

Trying to update column values in SQL Server based on time of insertion and getting “The column “ID” was specificed multiple times for “p””

Here is my query that’s throwing the “The column “ID” was specified multiple times for “p””: I’ve seen quite a few questions with the same error on SO but can’t seem to see what to apply in this scenario. Any help is greatly appreciated. Answer Unfortunately there is a lot broken with your statement. The error you are getting is

Rank Date based on today’s date

I have a simple date dimension, I’m attempting to write a Window function (without much luck..) to net the following result. where 1 is today and 0 is yesterday. What can I try next? I’m unsure what to search for. Answer Assuming the dates are continuous, we don’t even need analytic functions but instead we can just use DATEDIFF: Demo

Copy all values from source table to destination table dynamically in SQL Server. If there is some value in destination table then delete and insert

I have created 2 tables and populated the values in my source table. Now, I want to populate these values into the destination table dynamically and also check if there is any value in the destination table then delete all those values and insert them from the source. This is my approach which is not executing: Answer In your select

Advertisement