Viewing 15 posts - 316 through 330 (of 4,085 total)
This gives the same results but doesn't require creating a second temp table.
WITH status_ranges AS
(
SELECT
s.Starttime
,s.Endtime
,s.Status
,CASE WHEN s.Status = LAG(s.Status) OVER(ORDER BY s.Starttime) THEN 0 ELSE 1 END...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 14, 2019 at 11:15 pm
Both Jeff and Sumathi's solutions require two scans of the table. The following only requires one scan.
SELECT
tfu.rptMth
,SUBSTRING(MAX(tfu.rptMth + NULLIF(tfu.Buiding, '')) OVER(ORDER BY tfu.rptMth ROWS UNBOUNDED PRECEDING),...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 12, 2019 at 4:57 pm
The following is from ITPro Logical Query Processing: What It Is And What It Means to You
Figure 3: Logical query processing order of query clauses
1 FROM...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 8, 2019 at 8:11 pm
The last three things to be processed are : SELECT then TOP / OFFSET then ORDER BY
That's not what the SQL documentation says and that doesn't make sense either. ...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 8, 2019 at 8:00 pm
Just because your previous employer forbid you to use isnull does not mean it cant be used.
I never said it "can't" be used. I said it SHOULDN'T be used.
I...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 8, 2019 at 5:29 pm
As with all things SQL, it depends. I did a quick test using an index on VisitID and ActivityDateTime and Jonathan's original query won hands down based on the query...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 7, 2019 at 4:11 pm
Depending on your indexes, this may perform better.
WITH Last24Hrs AS (
SELECT
VisitID
,IdentifierID
,ActivityDateTime
,DATEADD(HOUR,-24,LAST_VALUE(ActivityDateTime) OVER (PARTITION BY VisitID ORDER BY ActivityDateTime ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) AS _24HrsBefore
FROM...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 7, 2019 at 3:50 pm
you can also use isnull function
Update APFinal
Set Comments = isnull(@Comments, 'No Comments Provided')
Where DocID = @DocID and ID = @ID
I recommend NOT using the ISNULL() function, which is why...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 6, 2019 at 9:17 pm
You want help troubleshooting an error message, but you didn't think that the text of the error message was relevant?
Why are you using a CASE expression rather than a COALESCE(). ...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 6, 2019 at 5:44 pm
Declare @tempAddress Table (
Id int
, Name1 varchar(10)
...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 5, 2019 at 7:07 pm
Also, as noted before, -1 has caused errors because of out-of-order date calcs. To me, it's just not worth the potential issues. Not to say you can't use it,...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 4, 2019 at 11:22 pm
You've been around long enough to know to use the Insert/edit code sample when entering code to preserve the formatting.
You're missing part of your code. You're using an alias that...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 1, 2019 at 7:29 pm
I think it's a circular argument. You don't use it, because it's not familiar, but it's not familiar, because you don't use it. I've been using the -1...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 1, 2019 at 6:26 pm
I think it's a circular argument. You don't use it, because it's not familiar, but it's not familiar, because you don't use it. I've been using the -1 variant for...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 1, 2019 at 4:20 pm
The standard pattern for getting the first day of the month is:
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()), 0)
Stick to that pattern, don't corrupt it with -1 tricks! That just makes it...
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
October 31, 2019 at 4:00 pm
Viewing 15 posts - 316 through 330 (of 4,085 total)