SELECT * FROM ( SELECT Product, SalesAmount, ROW_NUMBER() OVER (ORDER BY SalesAmount DESC) as RowNum, RANK() OVER (ORDER BY …
Tag: tsql
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 …
Count the number of times a date appears between 2 dates. SQL
I have 2 Dates for various items that are stored in a database as such (dd-mm-yyyy): ItemID|Date Arrived|Date Left 1 |01-02-1985 |01-06-2000 2 |01-02-1985 |01-04-2000 These item should …
need to have data till 3 dots in SQL
I am having data query with me it gives version of windows update DECLARE @variable VARCHAR SET @variable = ‘Windows client Update’ SELECT DISTINCT (v_GS_WINDOWSUPDATEAGENTVERSIO.Version0) AS …
TSQL query with aggregated data
I have a query that returns the min, max, avg and total for two different products. The client however wants the min, max, avg and total combined for both products. However I have an undesired result …
T-SQL – Copying & Transposing Data
I’m trying to copy data from one table to another, while transposing it and combining it into appropriate rows, with different columns in the second table. First time posting. Yes this may seem …
How to detect changes to values through a specific order
Given Id | RouteId | Milepoint | RoadCondition -: | :—— | ——–: | :———— 1 | A | 0 | X 2 | A | 1 | X 3 | A | 4 |…
Multiple rows in table with values from another table
I am struggling with following issue: Table1: Table2: Expected result: Basically I want to multiple rows in dates table with rows from User table. Is it somehow possible? (using TSQL).
How to set the user rights by passing the database name as Input parameter in a stored procedure?
How to set the user rights by passing the database name as Input parameter in a stored procedure? Declare @username nvarchar(100) Declare @databasename nvarchar(100) set @username = ‘ABC’ CREATE …
How to calculate difference between 2 time columns in distinct tables?
I need to calculate the difference between EntryHourSchedule (the ideal time) and EntryHourRegistered (the real time) of a worker’s assitance, but both are in 2 different tables: ScheduleDetail (* to …