Viewing 15 posts - 511 through 525 (of 2,648 total)

Here is the code produced by ChatGPT
SELECT *
FROM your_table
WHERE date_column >= DATEADD(month, DATEDIFF(month, 0, GETDATE()) - 1, 0)
AND date_column...
February 20, 2023 at 4:37 pm
Here is a test that shows using a separate UPDATE/INSERT is faster than a MERGE.
SET STATISTICS IO, TIME OFF
if object_id('dbo.t1','U') IS NOT NULL drop table dbo.t1;
if object_id('dbo.t2','U')...
February 20, 2023 at 12:31 pm
Sorry, but this script won't work well for large tables, especially with heavy use of IN() and NOT IN() operators. MERGE is usually faster than series of consecutive INSERT/UPDATE/DELETE...
February 20, 2023 at 10:02 am
Jeff Moden wrote:I'm kinda curious why anyone thinks that a separate overtime table is needed at all.
Well it can't go in the Employee table.
Heh... Ya think? 😀
Why is there...
February 20, 2023 at 1:59 am
I'm kinda curious why anyone thinks that a separate overtime table is needed at all.
Well it can't go in the Employee table.
February 20, 2023 at 1:26 am
I think you just need one table with
Overtime
ID (primary key)
EmployeeId (foreign key referencing the Employee table)
OvertimeDate
OTypeID ("D", "FoN", or "FN")
OvertimeHours
February 20, 2023 at 12:51 am
If you want to make it even faster you can add an index to the temporary table:
IF OBJECT_ID('tempdb..#pre_filtering') IS NOT NULL
DROP TABLE #pre_filtering;
;WITH... February 18, 2023 at 3:46 am
Try this instead, it splits it into 2 separate statements:
IF OBJECT_ID('tempdb..#pre_filtering') IS NOT NULL
DROP TABLE #pre_filtering;
;WITH pre_filtering AS
(
SELECT... February 18, 2023 at 3:28 am
Try this:
;WITH pre_filtering AS
(
SELECT DISTINCT
a.[DC],
...
February 18, 2023 at 2:55 am
Jonathan it is Microsoft SQL Server 2016
You asked the question in the SQL 2019 forum.
Try the code in the last comment I made.
February 18, 2023 at 2:20 am
You need a GROUP BY:
SELECT DC, UPC, stuff((select ', ' + MASTERCHAINNAME
from...
February 18, 2023 at 2:10 am
I have SSMS v18.5.1. When I tried to do it, it gave me an error namely 'STRING_AGG' is not a recognized built-in function name.
It's the version of SQL Server...
February 18, 2023 at 2:07 am
Create some test data in a consumable format (you should have done this):
DROP TABLE IF EXISTS #pre_filtering;
CREATE TABLE #pre_filtering (
DC VARCHAR(50),
...
February 18, 2023 at 2:02 am
Other thing is, SQL optimizer has not suggested any missing indexes in the actual execution plan.
We are on SQL Server 2017 EE.
You might have to rewrite the query to...
February 17, 2023 at 4:34 pm
[
Hi Jonathan,
Thanks for the inputs. I would think the last non-clustered idx is better to create. Also, I have a question on this, do we need to mention ROWID_OBJECT...
February 17, 2023 at 4:31 pm
Viewing 15 posts - 511 through 525 (of 2,648 total)