Viewing 15 posts - 376 through 390 (of 4,087 total)
Thank you all, appreciate it. I forgot to mention that the number of open/close parenthesis can vary. I'll see if I can work off your solutions to make that...
October 4, 2019 at 5:15 pm
Unfortunately, Jonathan's approach fails when you have nested parens. This approach works even with nested parens.
DECLARE @item VARCHAR(150) = 'All I want (for Christmas (or maybe my...
October 4, 2019 at 3:45 pm
You never populate your @Output
table.
Also, single-row WHILE
loops tend to perform worse than CURSOR
s. I see nothing in your code that would require to you process a single row...
October 4, 2019 at 2:19 pm
This is a variation on packing intervals. This approach assumes that there are no gaps. You need a slightly different approach if gaps are possible.
WITH status_starts AS
(
SELECT...
October 3, 2019 at 8:44 pm
You cannot define a CTE inside of a subquery as you are trying to do. The correct syntax is more like the following, although it's untested because you haven't supplied...
October 2, 2019 at 8:25 pm
I wonder if more of us ought to be using UTC or at least datetimeoffset for applications. There are more and more that are crossing time zones and it...
October 2, 2019 at 3:14 pm
This appears to perform better, because it only requires reading the table once. You should probably perform a more thorough analysis with a larger data set.
WITH window...
October 1, 2019 at 8:37 pm
The SELECT statement is ignored. This can be seen by running the following query, where the query runs without producing a "divide by zero" error.
IF EXISTS (...
October 1, 2019 at 8:25 pm
'getdate()'
is a string and is not a valid date.
Drew
October 1, 2019 at 8:11 pm
It seems that SE have a Code of Conduct change coming, which many of the moderators had concerns over. One moderator as a result of them disagreeing with the...
October 1, 2019 at 6:13 pm
You also need to specify what you mean by "equal or different". XML files can contain exactly the same information, but have a slightly different layout. Are they equal because...
September 30, 2019 at 3:00 pm
I believe that this is a variation on the bin packing problem. I think it's possible to solve without using a cursor, but I would need sample data and expected...
September 26, 2019 at 4:20 pm
Also, you should ALWAYS use QUOTENAME()
to insert brackets. Doing it the way you did opens you up to SQL injection.
Drew
September 26, 2019 at 4:12 pm
This is a packing intervals problem. Here is a solution that only requires one scan of the table.
;
WITH intervals AS
(
SELECT
a.rowId
,a.myDatetime
,a.myCount
,a.invalid
,CASE WHEN LAG(a.myDatetime, 1, '1900-01-01')OVER(ORDER BY a.myDateTime) <...
September 26, 2019 at 4:03 pm
Try this as well.
WITH Partitioned AS (
SELECT
memb_MembershipID
,memb_MemberID
,memb_type
,MIN(memb_type) OVER (PARTITION BY memb_MemberID) AS MinMemb
,MAX(memb_type) OVER (PARTITION BY memb_MemberID) AS MaxMemb
FROM dbo.Members
)
SELECT
memb_MembershipID
,memb_MemberID
,memb_type
FROM Partitioned
WHERE MinMemb <> 'Tier 1'
AND...
September 26, 2019 at 3:36 pm
Viewing 15 posts - 376 through 390 (of 4,087 total)