New answers tagged

3 votes
Accepted

How to sum up the distinct Total Time of an Event ignoring duplicate overlaps in Times?

All the complexity results from the overlapping intervals. If we pack the intervals so there are no overlaps, the solution is a straightforward group and sum. The following code uses Itzik Ben-Gan's ...
Paul White's user avatar
  • 83k
2 votes

How to sum up the distinct Total Time of an Event ignoring duplicate overlaps in Times?

Here is a solution that uses Run Length Encoding to compress overlapping time ranges - SCHEMA AND DESIRED OUTPUT DROP TABLE IF EXISTS dbo.EventTimes; CREATE TABLE dbo.EventTimes ( EventTimeKeyId INT ...
Caleb Carl's user avatar
0 votes

How do I filter down the latest Date from multiple columns

Here is a somewhat complex solution, but given your requirements this will work - CREATE TABLE #sample ( customer INT , civil_status VARCHAR(32) , civil_status_date DATE , power_status ...
Caleb Carl's user avatar
2 votes
Accepted

SQL Server remote insert fails, update works

"RPC is disabled on ServerA". RPC and RPC OUT are settings on the linked server definition, not on the target server. So just enable RPC OUT on the linked server definition and exec the ...
David Browne - Microsoft's user avatar
0 votes

Replace multiple words in a single value using SQL

I tweaked the query that Caleb provided to ensure we always stitch back the phrase in the order it was split and in order to do that i'm using OPENJSON split trick suggested by Aaron in an article. ...
lifeisajourney's user avatar
1 vote
Accepted

Replace multiple words in a single value using SQL

One way to do this as of SQL 2022, is to split the values in each customer row, replace them, and then zip them back up again. Setting the enable_ordinal flag to 1 in the STRING_SPLIT() function ...
Caleb Carl's user avatar
1 vote

In an Always On configuration, why do I have to open ports of the listener as well for the sql server engine itself for the listener ips?

listener01\instance01 You should never use instance names with a listener. Always use ports. You can also designate a non-standard availability group listener port. However, you also need to ...
David Browne - Microsoft's user avatar

Top 50 recent answers are included