Indicator based on the Categories

Greetings,

 I have data like this:
Category		        Amt	           Indicator
CC_EL			123.00
CC_Non_EL		300.00
RR_EL			200.00
RR_Non_EL		250.00

Open in new window


I need logic for an indicator that will exclude the Non_EL payments (Row 2 and Row 4) or include all the payments. Can someone please help?
pvsbandiAsked:
Who is Participating?
 
Randy PooleConnect With a Mentor Commented:
declare @ind varchar(1)
set @ind='Y'
select * from yourtable where (category like '%Non%' and @ind='N') or (@Ind='Y')

Open in new window

or if you want to build your string
select * from yourtable where (category like '%Non%' and Indicator='N') or (Indicator='Y')

Open in new window

0
 
Randy PooleCommented:
select * from yourtable where category like '%Non%'

Open in new window

Not 100% on what your looking for
0
 
Vikas GargBusiness Intelligence DeveloperCommented:
Update Table
set Indicator = case when Category like '%Non%'  then 'Include' else 'Exclude' end

Open in new window

This will set value in indicator to include and exclude

Hope this will help
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
pvsbandiAuthor Commented:
I'm looking for a SQL from that table with a case statement for the Indicator logic.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The above experts correctly answered your question.  
Why do you need a CASE?
0
 
pvsbandiAuthor Commented:
I'm not updating the table. I need to derive the logic based on SQL statement on that table.
0
 
pvsbandiAuthor Commented:
Also, if the Indicator is "Y", then the result shall be
Category		        Amt	        
CC_EL			123.00
CC_Non_EL		300.00
RR_EL			200.00
RR_Non_EL		250.00

Open in new window

If the Indicator is "N", then the result shall be
Category		        Amt	        
CC_EL			123.00
RR_EL			200.00

Open in new window

0
 
Scott PletcherConnect With a Mentor Senior DBACommented:
DECLARE @include_non_EL bit
SET @include_non_EL = 1

SELECT Category, Amt, Indicator
FROM tablename
WHERE
    (@include_non_EL = 1 OR Category NOT LIKE '%Non_EL%')
0
 
pvsbandiAuthor Commented:
Thank You!
0
All Courses

From novice to tech pro — start learning today.