Skip to content

Tag: sql-server

Update multiple columns/rows case statement SQL

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 …. …

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…

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:

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…