Solved

Indicator based on the Categories

Posted on 2014-09-09
9
63 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 14

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
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40312194
The above experts correctly answered your question.  
Why do you need a CASE?
0
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 

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:ScottPletcher
ScottPletcher 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now