i have table: id timestamp 1 31.10.2020 16:32:11 2 09.09.2020 09:15:49 3 22.04.2020 02:48:15 Table have huge amount these data. Column timestamp is data type “nvarchar”. And i …
Tag: sql-server
Sum rows with same Id based on type and exlude where SUM = 0
I have this table MOVEMENTS: I’m trying to get all the FatherId with the SUM of IN – OUT Movments > 0. So the result would be: FatherId = B not showing because SUM(MovementType = IN) – SUM (MovementType = OUT) = 0 I tried with That gives me the result grouped by FatherId, but I’m no…
Combining a recursive CTE with another query
I have a table of locations each of which can have a parent location I managed to create a recursive CTE which gives me parent location id (plus the original location id) for any given location id e.g. where LocationId = 3 would return: In another table I have a query which will return LocationId as one of th…
Use average of values in “where” clause
I want to select the top x value from a query where the average of valid values for a particular field is above 10. Why is this throwing an error? Answer Your code is throwing an error because avg() is an aggregation function and cannot be in the where clause. What you want seem to want is apply: The subquery
JOIN multiple tables based on one reference table and count records
I have these following tables: cars: id manufacturer ——————– 1 Nissan 2 Toyota 3 Honda 4 Volkswagen type: id type car_id ————–…
Remove text after a codeword
I have a list of company names that have been sent with their added company numbers. How can I remove these company numbers (of different length) in SQL? “Limited” if in the name needs to be …
Is it possible to use dynamic columns multiple times in a select?
I have some complex string replacement and I’m only permitted read-only access. I’d like to have several columns where each is dependent on the previous column so I can see if my substring and …
Query for R Machine Learning Services – Filtering Categories in Where Clause
I am trying to run a query in SQL Server using the Machine Learning Services extension. So this is the problem I am having; DECLARE @query NVARCHAR(MAX) = ‘ SELECT CATEGORY1,CATEGORY2 FROM TABLE WHERE …
Query help on sales transaction table
I have a table that contains transaction level sales data. I am trying to satisfy a reporting request as efficiently as possible which I don’t think I am succeeding at right now. Here is some test …
SQL – Assign jobs to workers – Alternative to a loop?
In SQL Server 2019, I have a table of unassigned tasks, and another table of workers who are available to work on those tasks. My requirement is to assign the workers evenly over the available tasks …