51 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
-1
votes
1
answer
173
views
Assign unique values in a set-based approach
Simplifying, I have the following data:
Col1
Col2
A
X
A
Y
A
Z
B
X
B
Y
B
Z
C
Z
I need to receive the following result:
Col1
Col2
A
X
B
Y
C
Z
In other words: For each value in the left column, I need to ...
0
votes
1
answer
64
views
Set-based approach to distributing a value SSMS TSQL
I have a table that includes a total debt and an annual repayment rate, payment start date and a calculated value for the first years prorata payment. I need to create/amend the table so that the ...
1
vote
2
answers
58
views
Selecting records from slowly changing table with a set of dates
I have a slowly changing table,a new row is created each time any of the source fields are changed. Some metadata is added to show when that version was valid. This is a simplified example(dates are ...
0
votes
1
answer
40
views
how to transfer this iterative solution to a set-based solution
/*
Stored Procedure
April 30, 2021
Mohamad Chaker
*/
USE CIS111_BookStoreMC
GO
--drop the procedure
IF OBJECT_ID('spAssetInfo') IS NOT NULL
DROP PROC spAssetInfo
GO
--Create the stored procedure
...
0
votes
0
answers
31
views
SQL Server Set-Based Update With Multiple Matches [duplicate]
I found this question, which presents the same situation. Trying to do a set-based update, and the table to be updated matchesmultiple rows in the table being used for update values. A minimal example ...
0
votes
1
answer
174
views
Is it possible to replace cursor in SQL when the query is hierarchical?
I have three tables in MsSQL to store data.
First one is the Children contains the following rows
ID,
Name,
Age,
FatherID,
SchoolID
The second one contains the data of their fathers, like this
...
2
votes
3
answers
275
views
Set based query to replace loop to populate all month end dates from given date for all records
I have a table that stores patient lab test results. There can be results from multiple tests like Albumin, Potassium, Phosphorus etc. First reading for each patient from each of these categories is ...
0
votes
1
answer
76
views
Can a SQL Select statement be converted to a Set-Based select?
I have an SP that creates and runs a SQL query. The end result is used for some reporting. This query though takes a long time to run (greater than 30 seconds is a long time and sometimes goes for ...
1
vote
1
answer
8k
views
PostgreSQL Inline Function Behavior
I wonder if anybody can please confirm the expected behavior of PostgreSQL Inlining?
From the Microsoft SQL world, any function which is determined to be inline, will be used in a single iteration ...
0
votes
1
answer
259
views
Update trigger does not update for all rows in a set based update query
I have the tables Cities and Countries with the following triggers:
When I update any City, it should insert a row into the Audit table saying 'The City with ID 'any ID' has been modified'. Cities ...
2
votes
2
answers
78
views
SQL Server: Most efficient way to look for set based on 2 columns
Edit:
I realized I asked the question wrong. What I really meant to ask was, "given a set of values for [Column B], check if there is a value in [Column A] that matches all of the set and no others."
...
0
votes
2
answers
87
views
SQL display ID of any customer who has never placed an order, using set-based operations only
Couldn't find anything on this, using set-based operations.
Not sure if I'm on the right track, but I have 2 guesses on how to do this, but I'm not sure if I'm even close, or if MINUS is the right set-...
-1
votes
1
answer
118
views
How to find updates to the status and who made it
I am working with a large SQL table, 186 columns, 257899 rows, and counting. It gets added to every time something is changed in the main data. This is part of the shadow tables that allow us to see ...
1
vote
2
answers
725
views
SQL - Extremely human readable, but I don't understand the concepts behind it
I seem to approach thinking about sql the wrong way. I am always writing things that do not work.
For example I need a variable. So i think:
DECLARE @CNT AS INT
SET @CNT = COUNT(DISTINCT database....
1
vote
1
answer
225
views
How to use set-based SQL in my query
I have a database set up to store all the input from every web form that I have created that looks like this:
(FormData)
----------------------
(PK) Id int not null,
(FK) FormFieldId int not null,
(...