Solved

Indicator based on the Categories

Posted on 2014-09-09
9
68 Views
Last Modified: 2014-09-09
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?
0
Comment
Question by:pvsbandi
9 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40312130
select * from yourtable where category like '%Non%'

Open in new window

Not 100% on what your looking for
0
 
LVL 15

Expert Comment

by:Vikas Garg
ID: 40312140
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
 

Author Comment

by:pvsbandi
ID: 40312182
I'm looking for a SQL from that table with a case statement for the Indicator logic.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Expert Comment

by:Jim Horn
ID: 40312194
The above experts correctly answered your question.  
Why do you need a CASE?
0
 

Author Comment

by:pvsbandi
ID: 40312223
I'm not updating the table. I need to derive the logic based on SQL statement on that table.
0
 

Author Comment

by:pvsbandi
ID: 40312234
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
 
LVL 21

Accepted Solution

by:
Randy Poole earned 250 total points
ID: 40312367
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
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 250 total points
ID: 40312393
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
 

Author Closing Comment

by:pvsbandi
ID: 40312792
Thank You!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question