I have a query in Entity Framework Core like below: I am dividing one currencyRate to another from 2 queries. There are 2 select queries. Only difference between queries is where condition. How to do this in one select query? Answer Pull both rows with Put an explicit order by on like Now you know the two rows you get
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
How do I pass a variable to a stored procedure to update a row in another database?
I need to get a value from one database for a customer and update another database with that value. The procedure below works but I need to have it go through table2 and update every customer in table1 with a matching CustomerID. I hate to use the word loop through but as I said, I am very new to this
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
Date in where clause returning 0 rows
I am trying to get data as follows WHERE DateCommande = ‘2018-09-05’ but it doesn’t work on my computer. Returns rows, including rows that show 2018-09-05 as the datetime value in a datetime column. However, on SSMS on my computer, if I add a WHERE clause, the query returns 0 rows: Answer yyyy-mm-dd hh:mm:ss.000 is not a language- and regional
Is it possible you instatiate a variable in SQL server using a select statement with another variable
I am attempting to DECLARE a variable then SET it’s value using a secondary variable which has already had it’s value set. I have tried: To no avail. The result of the final SELECT statement is null. The following works: but I have several tables linked via dependencies and to delete an entry I need to traverse the tables in
Best way to update the same column without using x update statements (if possible)?
I have a few questions regarding the following scenario – Consider this table (db<>fiddle here): I want to replace each class subject with a number code. For example: If I try to do this in one update statement, it won’t let me do that. The only thing I could think of was four separate statements using replace: This almost works,