Skip to content

Tag: sql-server

How to find rows in SQL DB with a definite word length?

Good day, I’ve got a column with text in my table, but i need to export words 17 letters long only in it. I tried to use but my query newer completes. This is an example of text cell REIGHT CAR DUMP T.M. “HOWO”, COMMERCIAL NAME A7, MODEL TOTAL 4 PIECES, WITHOUT PACKING IDENTIFICATION NUMBER …

Check for condition in GROUP BY?

Take this example data: I need an SQL statement that will group all the data but bring back the current status. So for ID 1 the group by needs a condition that only returns the Completed row and also returned the pending rows for ID 2 and 3. I am not 100% how to write in the condition for this.

How to get weekending having all approved records?

I have a table like below now want to get weekending ‘3/1/2020’ since it have all 1’s in isApproved like this I want to get list of weekending having all 1’s in isApproved Answer You can use aggregation and filter with a having clause: This works because isapproved only has 0/1 values.…

Update records in table from CTE results

I want to update the records in my table using CTE. And I’ve been trying with the insert function using CTE and it’s working. This is my query with the insert function: How to change that with the update function? i want to change to update function because when i use insert function,the previous …

Sum last two records including last record of a group

In SQL Server 2017, how do I sum the last two records and show the last record in a single query? Expected output: I tried using SUM with LAST_VALUE with ORDER BY Answer You can filter out rows by using the ROW_NUMBER() window function, as in: See SQL Fiddle.