erikTsomik
asked on
Help improving sql query
I need help improving this query
Select distinct pc.codeID,pc.codeName,pc.AwardAmmount,pc.description
from PromoCode PC
inner join lkupPromoCode_location PL WITH (NOLOCK) on pc.CodeID = PL.codeID
left outer join lkuppromoCode_product PP WITH (NOLOCK) on pp.codeID = PC.CodeID
left outer join lkupPromocode_package PPP WITH (NOLOCK) on PPP.codeID = PC.CodeID
WHERE PC.status = 1
and PC.StartDate <='#DateFormat(now(),"mm/dd/yyyy")#'
and PC.promoType = 0
AND ((pc.genEmail is NOT NULL and pc.genEmail = (select U.email from users U where u.userKey=#session.userid#)) OR pc.genEmail is NULL)
and DATEDIFF(D,pc.CodeIssueExpiry,GETDATE()) <= 0
and PL.LocationID IN (Select lkupPromoCode_location.locationID from lkupPromoCode_location where lkupPromoCode_location.codeID=pc.codeID and lkupPromoCode_location.type = 1)
and (ppp.packageID in
(Select lkupPromoCode_package.packageID
from lkupPromoCode_package
where lkupPromoCode_package.codeID=pc.codeID
and lkupPromoCode_package.packageID in (#ArrayToList(ListToArray(session.promocode.packageKey))#)
and lkupPromoCode_package.type = 1)
OR pp.productID in (
Select lkuppromoCode_product.productID
from lkuppromoCode_product
where lkuppromoCode_product.codeID=pc.codeID
and lkuppromoCode_product.productID in (#ArrayToList(ListToArray(session.promocode.productKey))#) and lkuppromoCode_product.type = 1 ))
Try to use
"and lkupPromoCode_location.typ e = 1"
instead of
"and PL.LocationID IN (Select lkupPromoCode_location.loc ationID from lkupPromoCode_location where lkupPromoCode_location.cod eID=pc.cod eID and lkupPromoCode_location.typ e = 1) "
If this works, try for other queries.
"and lkupPromoCode_location.typ
instead of
"and PL.LocationID IN (Select lkupPromoCode_location.loc
If this works, try for other queries.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you please provide table structure in sql file.