Skip to content

Tag: sql-server

SQL Group Multiple Results from Single Table

I have a table that contains a line entry for each item that I need to group into an output with all the values of multiple rows that have the same uniqueID into one column result. The ItemType will be different but the UniqueID and OtherData shouldn’t change as it’s tied directly to the UniqueID,…

Parse text and special characters from SQL Server

I have an issue with parsing text with special characters from XML in SQL Server. Let’s say I have a XML file Sample.xml which has the following data: I prepared the following SQL script which can parse everything except two sentences in the <TextType> attribute: First sentence to retrieve Second …

join equal or max

I want to join two tables by ‘EmployeeId’ and ‘CalendarMonthId’, but problem is that I want to connect record with the bigest CalednarMonthId if not exist equal. I use Azure Synapse SQL pool. Example data and code Base on this data I have problem with connect table: emp_contr, row: Emp…

get max value based on rank fucntion

I have sample data like below. I need to show the total sum from amount column irrespective of account column and need to get account which has maximum value in the amount column. I used the below script for the same. I am able to get the account which has maximum value in the amount column but total sum is

Combine two large multi-JOIN and GROUP BY queries

So I have one query that is performing one GROUP BY that requires a lot of joining to get it to perform aggregation of a row count basically Then there is a similarly structured query but performing a different aggregation on a row count. How would you nest the second query into the first query so that the fi…

SQL: Capturing first row in WHILE loop

I’m thinking my issue is based on how I’ve written the loop, but how it is written is how I’ve come to understand loops. So I’m really wondering if there is a way to consolidate this? As it sits, I have 2 sections: the first which captures the very first row, and it exists solely becau…

How to persist SQL Server system table records?

I am running a query that returns the last execution time for a stored procedure: I am getting the correct results, but if I run the query again in around 30 seconds, I don’t get any results. Is there a setting or command I need to set or add to persist the results? My goal is to find out what