Currently I'm working on rewriting old T-SQL procedures and today I find some difficulties.

There is a long query set in variable.

```
    set @Sql='
    ....
    ....
    where ('+ case when @p_TypeOfDataZak = 1 then 'cdn.MS_VatToDate(TrN_VatYear,
 TrN_VatMouth, TrN_VatDay) between cdn.MS_CDNDateToDate('+@DateFromv+') and cdn.MS_CDNDateToDate('+@DateTov+')'
                  else 'TrN_DataMag between '+@DateFromv+' and '+@DateTov
                   end +')
    ....
    ....
    exec (@Sql);

```

Now I want to modify it to the normal query, but I got issue with using between syntax in CASE expression. It should look like this.

```
where (case when @p_TypeOfDataZak = 1 then cdn.MS_VatToDate(TrN_VatYear, TrN_VatMouth, TrN_VatDay) between cdn.MS_CDNDateToDate(@DateFromv) and cdn.MS_CDNDateToDate(@DateTov)
              else TrN_DataMag between @DateFromv and @DateTov
               end )

```