Answer the question
In order to leave comments, you need to log in
How to fix an error in MSSQL query?
Moving from Oracle to MSSQL, rewriting functions and procedures. Here is the part of the request that gives the error:
select @g_count = count(*) from Award where awrd_personid = @personid
and awrd_deleted is null
and awrd_notinuse is null
and (awrd_awardtempid, awrd_discipline) in
(select awrs_reqawrdtempid, awrs_discipline from awardrestriction
where (awrs_competitionid = @competitionid or awrs_eventid = @eventid)
and awrs_persontype = 'Judge' and awrs_deleted is null);
..and (awrd_awardtempid, awrd_discipline) in..
Answer the question
In order to leave comments, you need to log in
... and exists
(
select 1
from awardrestriction
where
(awrs_competitionid = @competitionid or awrs_eventid = @eventid)
and awrs_persontype = 'Judge'
and awrs_deleted is null
and awrd_awardtempid = Award.awrd_awardtempid
and awrd_discipline = Award.awrd_discipline
)
I would replace the in construction with a direct join (INNER JOIN), that's all.
like this:
select @g_count = count(*)
from Award
/*Конструкцию in перенес вот сюда*/
join (
select awrs_reqawrdtempid, awrs_discipline
from awardrestriction
where (awrs_competitionid = @competitionid or awrs_eventid = @eventid)
and awrs_persontype = 'Judge' and awrs_deleted is null
) r on Award.awrd_awardtempid=r.awrs_reqawrdtempid
and Award.awrd_discipline=r.awrs_discipline
where awrd_personid = @personid
and awrd_deleted is null
and awrd_notinuse is null
--and (awrd_awardtempid, awrd_discipline) in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question