SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with the case condition
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Constraint Violating Yak Guru

India
252 Posts

Posted - 11/28/2012 :  00:58:34  Show Profile  Reply with Quote
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

USA
933 Posts

Posted - 11/28/2012 :  01:52:12  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 11/28/2012 :  02:16:07  Show Profile  Reply with Quote

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 


--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000