Skip to content

Tag: sql-server

Catch block not being executed

A QA tester in my company noticed that the catch block in an insert..exec statement is incorrectly attributing the error to the outer procedure instead of an inner procedure. The inner procedure is being called in several different places in various stored procedures. It’s working fine, but I was tasked…

Query with group by with CustID and amounts daily and MTD

I have the following data: ID username Cost time 1 test1 1 2021-05-22 11:48:36.000 2 test2 2 2021-05-20 12:55:22.000 3 test3 5 2021-05-21 00:00:0-0.000 I would like to count the costs for the username with a daily figure and a month to date figure in once table I have got the following This will return the mo…

Highest Mark in each course with student name

I want to get the highest mark in each course with the title of that course and student name who toke that course exam. and i have these tables , first one students id name 1 Jhon Doe 2 Sarah Doe and Courses table id title 1 Math 2 history and i made a table for connecting students with courses

Updating SQL Variable

I’m attempting to create a variable that will hold a value, which I will then later use to select from a table using the variable value. This works perfectly the first time around, but any time I try and change the parameters to update the variable it returns blank. Am I able to use the same variable wi…

Cumulative sum of a column

I have a table that has the below data. I wrote a query that will calculate the sum of cumulative rows and got the below output . Now I want to to filter the data and take only where the POOL <=300, if the POOL field does not have the value 300 then I should take the first value after

CASE Statement in WHERE Clause SQL Server

I’m having trouble sorting this out. I want to see the fiscal quarters for Date_Received. When the @ReviewPeriodQuarter = 1 then I want the Date_Received months 10,11,12. If @ReviewPeriodQuarter = 2 then I want the Date_Received months 1,2,3 etc. SQL Server doesn’t like the BETWEEN part of this. T…