I have been tasked with writing this simple query and am not sure where to go from here. I am trying to create a report that shows 3 columns: Date_Column, Id_Column, & Amount_Col. The table for Id_Column has different IDs based on a location column (in the table, but not in my query below). For the report…
Tag: tsql
How to combine multiple rows (one column) into One row
I am using SQL server 2017 and I have a scenario where I want to combine multiple rows of data into one row. Please see the below screenshot and let me know if that is possible. Thank you. Apologies if anything is missing. Please let me know the query on how to achieve this Answer SQL Server has supported str…
Unexpected results with consecutive + and – [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago. Improve this question I have the following queries : The result is : How is this output explained…
Find nearest day of week for a given date and day of week
For a pair of dates (date1, date2) = (Fri 2021-01-01, Wed 2020-01-01) I need to extract the day of week from date1 (Friday in this case) then find the nearest Friday (or whatever) for date2. The result for the above pair would be Fri 2020-01-03 (2 days after that Wednesday) and not Fri 2019-12-27 (5 days befo…
CASE WHEN with GROUP BY
I have the following query : I get this following error : Column ‘Status’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Answer
Split string without string_split (Sever 2012) [closed]
I would like to know if and if it’s possible how to split a string in to different columns. So first of all I have the table tabOld which contains: name 5522-rep__-4210-03-test-434907-emn-nt.pdf …
Group by Count of DateTime Per Hour by removing Duplicates?
I have a table named loginData: userName timestamp abc ‘2007-01-01 12:00:12 AM’ def ‘2021-01-01 12:09:12 AM’ abc ‘2021-01-01 12:40:12 AM’ abcde ‘2021-01-01 12:44:12 AM’ From this …
Create calculated field from MIN() and MAX() values of another column, grouped by unique ID
I have a table that looks like this, containing information about an object’s position and the length of time it existed for (age): Date ID Age x y 2021-03-25 20 1 531 295 2021-03-25 20 …
Subtotal of child records without COUNT?
ParentSub Table: ParentCode SubCode CompanyName MEGA1 MEGA1 Megacorp MEGA1 SUBC1 Subsidiary Company MEGA1 EASC1 East Coast Operations MEGA1 EURC1 Europe Company BIGLY ALPH1 Alphabet Company …
How can I output text until it is ascii in SQL?
How can I output text until it is ascii in SQL? Here is what I am trying to do: But in the end I am getting an empty string. Why? What am I missing here? I am expecting the value of the @output to be ‘text’ in the end of the script. UPDATE If I update the script to the