V
V
Vladimir2019-03-27 15:38:46
SQL Server
Vladimir, 2019-03-27 15:38:46

How to add a query if the condition in the case is true?

(SELECT c.ClassifierGroupId FROM ClassifierGroup c WHERE c.ClassifierId=
    (CASE WHEN @SupplierContractTypeClassifierGroupId = 0 THEN
      (2)
      ELSE
      (159)
      END)
    )

how do i write
AND c.ClassifierGroupId = @SupplierContractTypeClassifierGroupId
if c.ClassifierId = 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-12-06
@vovaburyii

SELECT ClassifierGroupId 
  FROM ClassifierGroup 
  WHERE 
    (CASE WHEN @SupplierContractTypeClassifierGroupId = 0 THEN
      IIF((ClassifierId=2) AND (ClassifierGroupId = @SupplierContractTypeClassifierGroupId), 1, 0)
      ELSE
      IIF(ClassifierId=159, 1, 0)
      END) = 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question