Viewing 15 posts - 1,516 through 1,530 (of 7,608 total)
Actually, best is often to force max values out of row, for every row. That is generally my preference, although naturally there are a few specific exceptions.
June 11, 2021 at 7:22 pm
Would have to see the query's use of col1 thru col8: in WHERE, JOINs, GROUP BY and even the SELECT itself.
SQL Server's missing index feature doesn't properly "understand" the importance...
June 9, 2021 at 9:31 pm
% returns a remainder from division.
So, 1.1 % 1 yields 0.1.
2.54 % 1 = 0.54
3.0 % 1 = 0.
June 9, 2021 at 9:26 pm
Came across an actual query which gave me an idea about another version of the test script for DISTINCT vs. GROUP BY.
create table #BalanceType (
id int...
June 8, 2021 at 2:37 pm
SELECT j.name AS job_name, jh.*
FROM (
SELECT jh.job_id, MAX(jh.instance_id) AS instance_id
FROM msdb.dbo.sysjobhistory jh
WHERE jh.run_status = 0...
June 7, 2021 at 6:22 pm
You need more than just year to accurately calculate age. Some people born in 2011 are 10 years old, but some are only 9 years old.
June 7, 2021 at 3:38 pm
My code works fine with that format of string:
;WITH test_data AS (
SELECT * FROM ( VALUES('(b) Joe Brown -12563'), ('(a) Mary Edwards -15425'),...
June 7, 2021 at 3:35 pm
Make catalog changes to that your new tempdb file set up takes effect the next time SQL starts up. You just have to delete the old tempdb files yourself. I...
June 7, 2021 at 3:22 pm
SQL provides a CASE expression to test for things like that:
SELECT ..., CASE WHEN PERSON.TERMINATION_DATE > '19000101' THEN 'N' ELSE '' END AS TERMINATION, ...
June 7, 2021 at 3:19 pm
LTRIM(RTRIM(SUBSTRING(name, CHARINDEX(')', name) + 1, PATINDEX('%[+-][0-9]%', name) - (CHARINDEX(')', name) + 1))))
;WITH test_data AS (
SELECT * FROM ( VALUES('(b) Joe Brown -12563'), ('(a)...
June 7, 2021 at 3:15 pm
It depends. If there's a large volume of data written to your SQL log even when there are no errors, then you should probably switch the logs more often (and,...
June 4, 2021 at 3:32 pm
No directly usable data to test with, but I think this should at least be close:
SELECT PH.*, PA.*
FROM dbo.PolicyHeader PH
OUTER APPLY (
SELECT TOP...
June 4, 2021 at 3:27 pm
Add WITH (TABLOCK) hint after the table name.
Examples:
UPDATE dbo.table_name WITH (TABLOCK)
SET ...
INSERT INTO dbo.table_name WITH (TABLOCK)
SELECT ...
June 4, 2021 at 3:00 pm
I think you can combine the first two queries into a single query, also avoiding having to rank all the totals:
WITH cteCombined AS
(
SELECT TOP (1) WITH...
June 3, 2021 at 9:10 pm
For the much more straightforward approach:
SELECT DISTINCT N
vs
SELECT N
...
GROUP BY N
my machine shows a slight edge for DISTINCT. That's what I've seen in normal usage, too. For a straight list...
June 3, 2021 at 4:01 pm
Viewing 15 posts - 1,516 through 1,530 (of 7,608 total)