Quantcast
Channel: SQL.ru: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 7251

Сложные условия во where в запросе процедуры

$
0
0
Добрый день.

Пробую сделать в запросе сложные фильтры во where в запросе процедуры

   FROM [KTMOTIS].[dbo].[ALARMS_KUZET] t1 where 
   [InsertTime] between @P2 and @P3
   and Dispt1=(case when @P4='1' then @P5 else Dispt1 end)


and Dispt1=(case when @P4='1' then @P5 else Dispt1 end)
-такой фильтр проходит, а как сделать что-то подобное
для таких условий в запросе:

if trim(ComboBox8.Text)='И незавершённые тр.' then
s:='(Vremopch>0 or Vremopoz is null) ';
if trim(ComboBox8.Text)='Только опоздания' then
s:='Vremopch>0 and Vremopoz is not null ';
if trim(ComboBox8.Text)='Только опоздания свыше 4 минут' then
s:='Vremopch >240';


@P4 пусть будет здесь значение ComboBox8.Text

и для таких условий
if ansiuppercase(trim(ComboBox2.Text))='МГОР АЛМАТЫ' then
s:='CALLSIGN_REAL like ''АРАЛ%'' or CALLSIGN_REAL  like ''МЕРКЕ%'' or CALLSIGN_REAL  like ''УЛАН%'''
else
if ansiuppercase(trim(ComboBox2.Text))='РЕГИОНЫ' then
s:='CALLSIGN_REAL not like ''АРАЛ%'' and CALLSIGN_REAL not like ''МЕРКЕ%'' and CALLSIGN_REAL not like ''УЛАН%'''
else
s:='CALLSIGN_REAL like '''+trim(ComboBox2.Text)+'%''' ;


@P4 пусть будет здесь значение ComboBox2.Text


и для таких условий

s:='Vremdoobj is not null and Vremdoobj<>'''''


@P4 пусть будет здесь значение '1'

Viewing all articles
Browse latest Browse all 7251

Trending Articles