
function GetQuestions(){
	var q = new Query();

	q.AddParameter("emptyRef", DB.EmptyRef("Catalog_Question"));

	q.Text =" WITH " +
    " 	AllQuestionsUnionAll(Question, QuestionDescription, SKU, SKUDescription, Answer, AnswerType, IsQuestionOfViolation, IsCountableQuestion) " +
	" AS ( " + 
    "    SELECT DISTINCT " + 
    "        USR_SKUQuestions.Question, " +
    "        Catalog_Question.Description, " +
    "        USR_SKUQuestions.SKU, " +
    "        Catalog_SKU.Description, " +
    "        USR_SKUQuestions.Answer, " +
    "        Catalog_Question.AnswerType, " +
    "        Catalog_Question.IsQuestionOfViolation, " +
    "        Catalog_Question.IsCountableQuestion " +
    "    FROM USR_SKUQuestions AS USR_SKUQuestions " +
    "    LEFT JOIN Catalog_Question AS Catalog_Question " +
    "    ON USR_SKUQuestions.Question = Catalog_Question.Id " +
    "    LEFT JOIN Catalog_SKU AS Catalog_SKU " +
    "    ON USR_SKUQuestions.SKU = Catalog_SKU.Id " +
    "    WHERE " +
    "        ( " +
    "            ( Catalog_Question.IsQuestionOfViolation =1 AND (Answer='Yes' OR Answer='Да') )  " +
    "            OR ( Catalog_Question.IsCountableQuestion = 1 AND TRIM(IFNULL(Answer, '')) != '' ) " +
    "        ) " +
    "        AND " +
    "        ( " +
    "            USR_SKUQuestions.ParentQuestion=@emptyRef " + 
    "            OR USR_SKUQuestions.ParentQuestion IN (SELECT Question FROM USR_SKUQuestions AS U2 WHERE (Answer='Yes' OR Answer='Да') AND USR_SKUQuestions.SKU=U2.SKU ) " +
    "        ) " +
    " " +
    "    UNION ALL " +
    " " +
    "    SELECT DISTINCT " +
    "        USR_Questions.Question, " +
    "        Catalog_Question.Description, " +
    "        null, " +
    "        null, " +
    "        USR_Questions.Answer, " +
    "        Catalog_Question.AnswerType, " +
    "        Catalog_Question.IsQuestionOfViolation, " +
    "        Catalog_Question.IsCountableQuestion " +
    "    FROM USR_Questions AS USR_Questions " +
    "    LEFT JOIN Catalog_Question AS Catalog_Question " +
    "    ON USR_Questions.Question = Catalog_Question.Id " +
    "    WHERE " +
    "        ( " +
    "            ( Catalog_Question.IsQuestionOfViolation =1 AND (Answer='Yes' OR Answer='Да') )   " +
    "            OR ( Catalog_Question.IsCountableQuestion = 1 AND TRIM(IFNULL(Answer, '')) != '' ) " +
    "        ) " +
    "        AND " +
    "        ( " +
    "            USR_Questions.ParentQuestion=@emptyRef " +
    "            OR USR_Questions.ParentQuestion IN (SELECT Question FROM USR_Questions WHERE (Answer='Yes' OR Answer='Да')) " +
    "        ) " +
    ") " +
	" SELECT " + 
	"     Question AS Question, " + 
    "     QuestionDescription AS QuestionDescription, " + 
	"     SKU AS SKU, " +
    "     SKUDescription AS SKUDescription, " +
	"     MAX(Answer) AS Answer, " +
	"     1 AS IsQuestionOfViolation " +
	" " +
	" FROM AllQuestionsUnionAll " +
	" WHERE " +
	"     IsQuestionOfViolation " +
	" GROUP BY " +
	"     Question, " +
    "     QuestionDescription, " +
	"     SKU, " +
    "     SKUDescription " +
	" " +
	" UNION ALL " +
	" " +  
	" SELECT " +
	"     Question, " +
    "     QuestionDescription, " + 
	"     null, " +
    "     null, " +
	"     SUM(Answer), " + 
	"     0 " +
	" FROM AllQuestionsUnionAll " +
	" WHERE " +
	"     IsCountableQuestion " +
	" GROUP BY " +
	"     Question, " +
    "     QuestionDescription ";

    return q.Execute();
}