Skip to content
Advertisement

Tag: tsql

Using a Scalar Function that expects a Table Parameter inside an Apply block

TLDR: I have a scalar function, that expects a table-valued parameter and returns the XML representation of that table. Now I need to use this function in a larger Update statement, where the table-parameter of the function is generated by inner Select statements. Hi, We have an XML type definition, say [dbo].[XmlTestType], that looks like something this: It basically represents

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 message

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 local ,product ,price ,IIF(MIN(Product)

Transform Columns to Rows dynamically using T-SQL

I have the following table where I need to transform Columns to Rows tbl_Survey: I need to have the following result: To have this result I used the following code: But, my Quest_1, Quest_2, Quest_3 values could potentially be changed / or even added a new once… Are there ways to code them, so it can be used for any

Advertisement