Link to home
Start Free TrialLog in
Avatar of Sam Runyon
Sam Runyon

asked on

I need to take the value and make it say ">30 Days"

I need to take the value and make it say ">30 Days"

Here is what my statement looks like

CASE WHEN Cast(CHEMVAL.value AS NUMERIC(5, 1)) = 0 THEN Cast(CHTKVOL.value AS NUMERIC(5, 1)) ELSE Cast(CHTKVOL.value AS NUMERIC(5, 1)) / Cast(CHEMVAL.value AS NUMERIC(5, 1)) END as [Days Left at Current Rate]

 if the value is 30 or greater just display ">30 Days"
Avatar of lcohan
lcohan
Flag of Canada image

I think a CASE in the CASE can be added like:

CASE WHEN Cast(CHEMVAL.value AS NUMERIC(5, 1)) = 0 
	THEN Cast(CHTKVOL.value AS NUMERIC(5, 1)) 
	ELSE 
	CASE WHEN (Cast(CHTKVOL.value AS NUMERIC(5, 1)) / Cast(CHEMVAL.value AS NUMERIC(5, 1)) ) >= 30 
		THEN ‘>30 Days’  ELSE Cast(CHTKVOL.value AS NUMERIC(5, 1)) / Cast(CHEMVAL.value AS NUMERIC(5, 1)) END
END as [Days Left at Current Rate]

Open in new window

That will fail because you can't convert the string ">30 Days" to a numeric value.  You'd need to cast the computation to a string to avoid that issue.
Avatar of Sam Runyon
Sam Runyon

ASKER

Scott could you help with the context of the problem.. I am new.. learning at a slow place. :)

Sam
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your choices are:

1. either you generate the complete string you want to show in the end in SQL; i.e. currently you probably append the word "days" somewhere in the UI or report, wherever it goes into in the end. So now you'd have to remove that, generate the complete string in SQL, and in the UI show only what came from SQL

or

2. Generate those ">30 days" in your report or UI rather than in SQL.

#2 is probably more straightforward. If you tell what is that end-user UI, we can tell more specifically how to achieve that. For example, in SSRS report it would be easily achieved by an expression like =Iif(DaysLeftatCurrentRate.Value<=30, DaysLeftatCurrentRate.Value, ">30 days")