Viewing 15 posts - 271 through 285 (of 1,464 total)
All those UNION ALLs could also be an issue. You may want to consider a Divide-n-Conquer path.
Create a #TempTable, then break the massive union all up, inserting each set of...
February 1, 2021 at 8:55 am
Secondly, this line in your WHERE clause will ALWAYS cause a full table/index scan.
and (a.BenefitsID=@BenefitsID OR @benefitId = 'ALL')
The reason for this is that SQL has to...
February 1, 2021 at 6:29 am
Firstly, your query is hitting the same table 8 times. This can be vastly improved by using a cross-tab query to only hit the table once. The following 2 queries...
February 1, 2021 at 6:26 am
I believe that APPLY was introduced in 2005
https://www.red-gate.com/simple-talk/sql/t-sql-programming/sql-server-apply-basics/
https://www.mssqltips.com/sqlservertip/1958/sql-server-cross-apply-and-outer-apply/
January 29, 2021 at 12:57 pm
January 29, 2021 at 10:57 am
@DesNorton - I don't think sp_ExecuteSQL would actually diminish the danger. If the @WeatherFieldName variable had a semicolon in it, followed by a query - I believe it would...
January 28, 2021 at 5:34 pm
Having a large list of fields, you are definitely going to have some ugly long code.
If SQL Injection is your only objection to Dynamic SQL, then you can mitigate the...
January 28, 2021 at 4:00 pm
You can use OUTER APPLY
SELECT [Car type] = C.CarType
...
January 28, 2021 at 10:24 am
A small perf improvement on @shane.green code
INSERT INTO #FieldValues ( Field1, Field2, Field3 )
SELECT Field1 = MAX( CASE
...
January 28, 2021 at 7:03 am
You have nothing that binds the 3 records together and nothing that orders the records. So there is no way to consistently achieve what you are trying to do.
January 26, 2021 at 10:55 am
I'm too lazy to create tables to test. But I believe that there are 2 ways that you could achieve this.
SELECT Table1.EMPID
FROM ...
January 21, 2021 at 6:06 am
SQL is not Excel. By default, it cannot see the value in the previous or next row.
However, Window Functions are going to be your new best friend for this task,...
January 19, 2021 at 8:47 am
Deadlocks are not my strong point. That said, deadlocks occur when 2 or more processes are waiting on each other to access the same resource. The deadlocks can occur at...
January 19, 2021 at 8:40 am
This may be what you are looking for .
SELECT *
FROM COMPANY
WHERE PRODUCTS IN ( 'Product1', 'Product2', 'Product3', 'Product4' );
January 15, 2021 at 5:33 am
If you are only interested in specific employees, then put the filter on the Employee table
WITH cteHours AS (
...
)
SELECT e.identifier
, AllHours = ISNULL(SUM(h.[HOURS]),0)/60.00
FROM cms.dbo.Employee AS e
LEFT JOIN...
January 13, 2021 at 12:28 pm
Viewing 15 posts - 271 through 285 (of 1,464 total)