sql - How to return mulitple columns in a WHERE clause CASE statement -
my stored procedure accepts parameters , 1 of them @searchby
can contain couple of different values iisapppool
, scheduledtask
, windowsservice
, com+
, serviceaccount
, etc shown in case statement
below.
depending on value go , value in value's corresponding column.
scomponenttype
contain iis_app_pool
, sched_task
, win_service
or com_plus
irrespective of @searchby
is.
i struggling clause, needs case
statement.
the following working fine.
where sdate between @fromdate , @todate , case @searchby when 'iisapppool' scomponentname when 'scheduledtask' scomponentname when 'windowsservice' scomponentname when 'com+' scomponentname when 'serviceaccount' sserviceaccount when 'server' sservername when 'imccreference' simccreference when 'user' smanager end like('%' + @searchcriteria + '%')
what looking like:
where sdate between @fromdate , @todate , case @searchby when 'iisapppool' scomponentname , scomponenttype = 'iis_app_pool' when 'scheduledtask' scomponentname , scomponenttype = 'sched_task' when 'windowsservice' scomponentname , scomponenttype = 'win_service' when 'com+' scomponentname , scomponenttype = 'com_plus' when 'serviceaccount' sserviceaccount when 'server' sservername when 'imccreference' simccreference when 'user' smanager end like('%' + @searchcriteria + '%')
i know not possible tried following in addition have above don't know how write code if @searchby
not app pool, scheduled task, windows service or com+ component:
and scomponenttype = case @searchby when 'iisapppool' 'iis_app_pool' when 'scheduledtask' 'sched_task' when 'windowsservice' 'win_service' when 'com+' 'com_plus' end
i hope making sense.
can not use searched case statement rather simple case statement? e.g.
and case when @searchby = 'iisapppool' , scomponenttype = 'iis_app_pool' scomponentname when @searchby = 'scheduledtask' , scomponenttype = 'sched_task' scomponentname when @searchby = 'windowsservice' , scomponenttype = 'win_service' scomponentname when @searchby = 'com+' , scomponenttype = 'com_plus' scomponentname when @searchby = 'serviceaccount' sserviceaccount when @searchby = 'server' sservername when @searchby = 'imccreference' simccreference when @searchby = 'user' smanager end like('%' + @searchcriteria + '%')
Comments
Post a Comment