Skip to content

Tag: tsql

Returning Records by Week

I’m trying to come up with a way to return a result set from the below data without a loop that shows the number of records by Team for a particular date range by week. I’ve got a Date table (https://www.mssqltips.com/sqlservertip/4054/creating-a-date-dimension-or-calendar-table-in-sql-server/) th…

How to include OPENJSON in View?

My JSON object is stored in the table (single cell). Right now, I’m reading the cell and saving the value to @json NVARCHAR(MAX) , but that obviously doesn’t work in views. How can I do something like this? Answer You can use cross apply to apply openjson() to each and every row of your table:

Select data from multiple existing tables dynamically

I have tables “T1” in the database that are broken down by month of the form (table_082020, table_092020, table_102020). Each contains several million records. There is a second table “T2” that stores a reference to the primary key of the first one and actually to the table itself only…