TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
NA
1.6k
281.4k
WHEN Add optional parameters on join query become very slow so How to
Aug 4 2020 9:05 PM
I work on SQL server 2012 I face issue when add this statement it take 9 minutes to display 900 rows only
SELECT
fmat.Value
as
PLID,c.CodeType,
COUNT
(
DISTINCT
tr.PartID) [#partsHasCodes]
into
#partsHasCodes
FROM
Parts.TradeCodes tr
WITH
(NOLOCK)
INNER
JOIN
Parts.Nop_Part pt
WITH
(NOLOCK)
ON
pt.PartID = tr.PartID
INNER
JOIN
Parts.Nop_PartsFamilyAttribute fmat
WITH
(NOLOCK)
ON
fmat.PartFamilyID=pt.PartsFamilyID
AND
fmat.[
Key
]=20281007
inner
join
#TempPlAndCodeType c
on
(c.CodeTypeId=tr.CodeTypeID)
AND
(c.PLID
is
null
OR
fmat.Value=c.PLID)
GROUP
BY
fmat.Value,c.CodeType
without add this statement below
AND (c.PLID is null OR fmat.Value=c.PLID)
query take 3 minute to display 900 rows and after add
AND (c.PLID is null OR fmat.Value=c.PLID)
it take 9 minutes
Are there are any way to make query above to be optional without take too much time
PLID IS optional if it have value then get his value and code type
if PLID not have value then select data based on code type
so why it take too much time
Reply
Answers (
2
)
Create a Table script
User defined table in Sql Server