I have looked at similar questions previously but they seem to update a single column with multiple case conditions and the one answer I found for multiple columns seems a little long. Let’s say I have a table like this: Column_1 Column_2 Column_3 Column_4 Column_5 First Value 1 Second Value 2 …. …
Tag: sql-server
I want to update a string in a table
I have a table, content_history with a column, doc_filename, and each row has a string value. Each string has a | and the portion in front of the | is a filepath. I want to replace that portion of the string with the correct filepath if it doesn’t already match. What is the best way to go about doing th…
How to add a where clause and / or a order by to a update statement with declare
I am currently testing using the declare update statement below. This will update my StackCustomerAltID numericly from 1 thourgh 501. But I need to figure out how to add a where clause or a order by using my Customer column in asc order. here is the where clause I need to add (where DelFlg = 0 and Customer &l…
Calculate the time period a certain field is overlapping in SQL Server
I am currently trying to figure out the overlapping time period between records. I already have a query that indicates if it is overlapping another field with ‘yes’ and ‘no’. But I need to have the exact duration of the overlapping time period when the field has ‘yes’ as in…
SQL Insert into duplicates
My code is as follows: I should explain the SUM(), there are differing dates on schedule such as I want to get all the “count” of “serviceId” beyond today hence the ‘date >= GETDATE()’ Basically I want the table to look like so: I am able to get the values but I get them…
Adding custom value to SELECT
I have this query: I want to use the record_dt of the second query as a replacement of the record_dt in the first query. I want to do that by linking the values on the part_id since they both have it. First query is giving a list of record_id that has part_id, the second query is taking the latest record_dt
How can I delete record based on date?
I have a set of data with DateTime type in SQL. I want to delete whatever data belong to a specific date for ex: 2021-11-02 21:07:52.663. if I have value like above I want to delete records using just date. 2021-11-02. Answer This will compare the date part of your datetime to the desired date:
How can I convert a date that’s in “yyyy-mm/dd” to “yyyy-mm-dd”
I have a column that’s called appt_date (varchar(50)) that’s in the format of YYYY-MM/DD and I want to convert it to YYYY-MM-DD I’ve tried several replace, convert, cast functions and solutions found on here but I still end up with the same result. I greatly appreciate the help in advance. A…
Query to sum the top “n” records
I would like to sum the forecast qty column for only the first “n” date records. For example for each item number the earliest(or first) three date records Current Query: Table Desired Result Answer Assign a row number to each record, partitioning by Item (this will start a new row counter for eac…
Get Start and End date from multiple rows of dates, excluding weekends
I’m trying figure out how to return Start Date and End date based on data like in the below table: Name Date From Date To A 2022-01-03 2022-01-03 A 2021-12-29 2021-12-31 A 2021-12-28 2021-12-28 A 2021-12-27 2021-12-27 A 2021-12-23 2021-12-24 A 2021-11-08 2021-11-09 The result I am after would show like …