I’m unsure how to proceed with this or what to search for but here goes my attempt at explaining what I’m trying to do! There may be multiple ways to figure this out as well. I am working on a …
Tag: sql-server
Dynamically name a column based on a WHERE condition
Objective: I am running a query on a weekly basis and would like one of my column to return the ISO_WEEK number with the prefix ‘W’. For example: W1. More specifically, I would like to reproduce the …
columns in SQL Server
I have a sample table below: Flight Airport Datetime 123 AID_X_YZ 5/5/2018 12:52:00 AM 123 AID_X_YZ–> NRT_X 5/6/2018 5:50:00 AM 123 NRT_X …
Recursively calculate product weights in product tree
I’m developing a software for Consumer price index calculation and one step of all calculation is to calculate product weights in product category. This should be done in SQL server side. I have MS …
SQL Windowing Ranks Functions
SELECT * FROM ( SELECT Product, SalesAmount, ROW_NUMBER() OVER (ORDER BY SalesAmount DESC) as RowNum, RANK() OVER (ORDER BY …
SQL-Server I’m getting crazy with workday calculation with datepart
I’m working on SQL-Server 2012 and have the following code example to get workdays between two dates DECLARE @StartDate AS date DECLARE @EndDate AS date SET @StartDate = ‘2019/02/18’ — this is a …
Filter data in one table based on data in another table
I have two tables presented below. First table contains information about indexes. Each index can be applied to one or more columns. Second table contains set of pairs: table name – column name. I …
join tables time difference of 10 minutes [datetime2](7) NULL
I want to join the values of 2 tables date for specific minutes . say data join for same date but hours can be + or – 10 minutes in difference. select * from table1 inner join table2 where table1….
Dynamic Extraction of text – SQL
I have a column with values in the following format: Successfully refunded 1 units of product 11111111 Successfully refunded 1 units of product 22222222 Successfully refunded 1 units of product …
How to create indexed view of children count
I am trying to take a table with a parent child relationship and get the number of children. I would like to create an indexed view of the number of children by utilizing COUNT_BIG(*). The problem is …