Skip to content

Tag: tsql

Looping in SQL with TempTable

I am new to SQL Server, can you please help me to write query for my scenario? I have this Table1 : Input to my stored procedure is a PolicyNumber e.g 1234 and the code should return 5 rows. I need to cover these cases: If the first payment is not cancelled, I need return that row. If the first

Dynamic Pivot Table by Month

I’m trying to create a dynamic pivot table in SQL that will report based on month and year. I did a bunch of research and was able to come up with the below query: I am able to print the @column variable successfully, but the problems happen when I try to set it in the @dynamic variable. The error messa…

SQL- Find the price of the smallest product in a store

I would like to find the price of the smallest product in a store and in addition, in another column, populate this price in all the products of the same store. Here is my table and the desired result in the “results” column: Table1 Here is my request but it does not populate the price: SELECT loc…