Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with the case condition

Author  Topic 

mohan123
Constraint Violating Yak Guru

252 Posts

Posted - 2012-11-28 : 00:58:34
hello all i have a problem with case condition here i have to call the condition M.MetricType = 'P'

it should show this one : CASE
WHEN NU.FromFrequency = 1 THEN 'One'
WHEN NU.FromFrequency = 2 THEN 'Two'
WHEN NU.FromFrequency = 3 THEN 'Three'
WHEN NU.FromFrequency = 4 THEN 'Four'
WHEN NU.FromFrequency = 5 THEN 'Five'
ELSE ''
END +' '+'to'+' '+
CASE WHEN NU.ToFrequency = 6 THEN 'One'
WHEN NU.ToFrequency = 7 THEN 'Two'
WHEN NU.ToFrequency = 8 THEN 'Three'
WHEN NU.ToFrequency = 9 THEN 'Four'
WHEN NU.ToFrequency = 10 THEN 'Five' END +' '+CASE WHEN NU.ToFrequency = 6 THEN 'time' WHEN
NU.ToFrequency = 10 THEN 'times Or greater' else 'times' AS Frequency

WHEN M.MetricType = 'o' THEN

it should show NU.FromOperator +nu.FromFrequency+nu.ToOperator ELSE '' END AS MeasureRanges,

how to write case condition for both the statements in storeprocedure

in clarity :

CASE WHEN
M.MetricType = 'P' THEN above statement should come

WHEN M.MetricType = 'o' THEN below statement should come

suggest me

P.V.P.MOhan

nathans
Aged Yak Warrior

938 Posts

Posted - 2012-11-28 : 01:52:12
Hopefully I understand... does this help?


declare @MetricType char(1);
set @MetricType = 'P'

declare @Frequency varchar(100);

if @MetricType = 'P'
begin

select @Frequency = '<above statement>'
end else
if @MetricType = 'o'
begin

select @Frequency = '<below statement>'
end


print @Frequency


Nathan Skerl
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-11-28 : 02:16:07
[code]
CASE WHEN M.MetricType = 'P'
THEN CASE WHEN NU.FromFrequency = 1 THEN 'One'
WHEN NU.FromFrequency = 2 THEN 'Two'
WHEN NU.FromFrequency = 3 THEN 'Three'
WHEN NU.FromFrequency = 4 THEN 'Four'
WHEN NU.FromFrequency = 5 THEN 'Five'
ELSE '' END +' '+'to'+' '+
CASE WHEN NU.ToFrequency = 6 THEN 'One'
WHEN NU.ToFrequency = 7 THEN 'Two'
WHEN NU.ToFrequency = 8 THEN 'Three'
WHEN NU.ToFrequency = 9 THEN 'Four'
WHEN NU.ToFrequency = 10 THEN 'Five' END +' '+
CASE WHEN NU.ToFrequency = 6 THEN 'time'
WHEN NU.ToFrequency = 10 THEN 'times Or greater'
else 'times' END
WHEN M.MetricType = 'o' THEN CAST(NU.FromOperator AS VARCHAR) + ' ' +CAST(NU.FromFrequency as varchar) + ' ' + CAST(NU.ToOperator as varchar) ELSE ''
END AS Frequency
[/code]

--
Chandu
Go to Top of Page
   

- Advertisement -