I am trying to convert week of the date based on my criteria. My date condition: if my @date is less than 4 AM, then @date – 1, else @date declare @dates datetime set @dates = ‘2019-01-01 03:59:59’…
Tag: sql-server
Transpose Rows Into Columns by Delimiter Column Name and Column Title
I’m slightly stuck on this issue and need some SQL assistance please. Iv got a hierarchy table from someone who needs help transposing it and putting them into actual columns of another table. Here is …
SQL Server : “invalid column name” error after GROUP BY on subquery
I am trying to perform the following query on a SQL Server database table with a GROUP BY on a column which results from a CASE statement done on a subquery: SELECT AVG(sales) as avg_sales, …
Calculate Mode of points that fall within each polygon
I have two tables in SQL Server. Address Points & District Regions Both have geom fields and share common SRID The Address Points have an integer value field. For each district I want to take the …
Query SQL with similar values
I have to make a query to a base using as a comparison a string like this 12345678, but the value to compare is this way12.345.678, if I do the following query it does not return anything. SELECT * …
Grouping sql result by a specific criteria
i am writing a query that supposed to show for a set of users, what emails he/she received, and if the email was open or not. This is the result of the query: Product | Year | Month | …
detect cycles in a graph in SQL using recursive common table expression
Given a directed graph having a cycle, how do you detect and list the cycle using only standard SQL ? input = graph edges and a root node from which we compute the transitive closure. Output = …
SQL query for column numbers
I have a table with information like : With these 2 columns I need to pull a column like “New Column” which is basically serial numbers of pages for each order. I tried ROW_NUMBER() OVER(ORDER BY …
Calculate the numbers of week names
I tried to edit but I have not knowledge about the number of weeks: declare @from datetime= ‘2019-06-01’ declare @to datetime = ‘2019-06-19’ select datediff(day, -3, @to)/7-datediff(day, -2, @from)…
Pulling another row if it meets criteria from the first pulled row
Need to compare some accounts, which some people have two of, an admin account and a regular account. These admin accounts list their regular account as their manager and all of the admin accounts …