SSRS if statement to return a blank value - ssrs-2008

I have two columns in my IIF statements called DEPT_CODE and UNIQUE_CODE
what i'm trying to do is return "blank" if the UNIQUE_CODE equals to 2343 else return the DEPT_CODE value.
IIF UNIQUE_CODE = "2343" Then return " " ELSE return DEPT_CODE value

You've basically written it..
=IIF(Fields!UNIQUE_CODE.Value = "2343", "", Fields!DEPT_CODE.Value)
Note that this returns an empty string. In your pseudo code you had a single space. Change as required.
The IIF statement works as follows.
IIF( <boolean expression to evaluate> , <return this if true>, <return this if false> )

Related

ELSE value not executed in CASE expression PostgreSQL

I'm using CASE expression to display "NamaAyah" or "NamaIbu" or "NamaWali", and if all of them is empty, the default value will display "ORTU-'NomorPokok' ".
But the default value not displayed, it just displays symbol "-" in my table. I think the value in ELSE statement not executed.
Postgre Version : PostgreSQL 9.4.15
This is my code
SELECT
"MahasiswaID" AS "PERSONID","NomorPokok" AS "KODE",
UPPER(CASE
WHEN "NamaAyah" <> '' THEN "NamaAyah"
WHEN "NamaIbu" <> '' THEN "NamaIbu"
WHEN "NamaWali" <> '' THEN "NamaWali"
ELSE 'ORTU'||'-'||"NomorPokok"
END) AS "NAMALENGKAP"
FROM "MasterMahasiswa" ORDER BY "KODE"
and this is the result
The expression you have can simpler be:
ELSE 'ORTU-'||"NomorPokok"
Apart from that, the only reasonable explanation for what you display is that there are literal - in one or more of your columns "NamaAyah", "NamaIbu" and "NamaWali". Did you check that?

How instead of Numeric display string as '-' in a CASE statement

I have a simple CASE statement where in my ELSE block numeric column I want to display as '-'.
But it gives me an error
Arithmetic overflow error converting varchar to data type numeric.
How would I do that?
I want it like this:
SELECT
CASE WHEN ChargeName = 'Premium' THEN CompanyCommissionPercentage ELSE '-' END AS CompanyCommissionPercentage
,CASE WHEN ChargeName = 'Premium' THEN RemitterCommissionPercentage ELSE '-' END AS RemitterCommissionPercentage
,CASE WHEN ChargeName = 'Premium' THEN RemitterCommission ELSE '-'END AS RemitterCommission
,CASE WHEN ChargeName = 'Premium' THEN GrossCommission ELSE '-'END AS GrossCommission
FROM #tmpAccountsPayable
`SELECT
CASE WHEN ChargeName = 'Premium' THEN CAST(CompanyCommissionPercentage as varchar(10)) ELSE CAST('-' as varchar(10)) END AS CompanyCommissionPercentage
FROM #tmpAccountsPayable`
Here's a picture of where in excel you can set formatting to a -
You may be better off passing in a zero instead of the dash and allowing excel formatting to make the 0 a - (assuming of course the output is going into excel)
Notice below in E20 the 0 value is converted to a - when accounting format (comma format) is used.
Also notice how a regular dash is left aligned while the accounting - is indented.

How to get all records from Crystal Report using default parameter values

I have a Crystal Report which has two paramaters: {?EmailVerifyStatus} and {?Company}. I want it so that when the two paramaters are blank the report gets all the records.
Here is my current code:
(if {?EmailVerifyStatus}='Y' THEN {PREH.udEmailVerify}='Y'
ELSE IF {?EmailVerifyStatus}='N' THEN {PREH.udEmailVerify}='N'
ELSE 1=1)
and
(if {?Company} <> '0' then not (IF "," & ToText({PREH.PRCo},0,'') & "," IN "," & {?Company} & "," THEN 0=1 ELSE 1=1) else 1=1 )
But, it is only returning the records with a 'Y' value.
You have to check if parameters have set a value with the hasvalue() function. Then you can do this:
(not(hasvalue({?EmailVerifyStatus})) or {PREH.udEmailVerify} = {?EmailVerifyStatus}) and
(not(hasvalue({?PRCo})) or {PREH.Co} = {?Company})
I dont understand your second condition ...

How does sql evaluate ISNUMERIC(ISNULL(VALUE, 'blah'))

My assumption was that it would return a true if that value was numeric (within the isnumeric range) but FALSE if the ISNULL returns 'blah'. Seems like my assumption was off...
I'm using the it in the following way
case when ISNULL(ISNUMERIC(c.npinumber), 'blah') = 1
then c.NPiNUmber
else 'not valid: ' + c.NpiNumber
end as npi
Building on Dhruvesh's answer,
case
when ISNUMERIC(c.npinumber) = 1 then c.NPiNUmber
else 'not valid: ' + c.NpiNumber
end as npi
Will produce NULL anytime NpiNumber is NULL. The reason is that NULL + any string will still return NULL. The solution is to simply use the COALESCE function
case
when ISNUMERIC(c.npinumber) = 1 then c.NPiNUmber
else 'not valid: ' + COALESCE(c.NpiNumber, 'NULL VALUE')
end as npi
select ISNUMERIC(ISNULL(NULL, 'blah')),
ISNUMERIC(ISNULL(1234, 'blah')),
ISNUMERIC(ISNULL('ab', 'blah'))
Returns 0, 1, 0 - so your logic is correct.
When SQL's not behaving I like to simplify my query. Try running the query without your case statement first. If the results look right, then add additional logic.
What collation is your database? It's always a good idea to keep your column names properly cased (I'm looking at that all-lowercase column name over there...).
You don't require ISNULL. ISNUMERIC will return 1 if it's numberic or 0 if it's NULL or non-numeric.
case
when ISNUMERIC(c.NpiNumber) = 1 then c.NPiNUmber
else 'not valid: ' + c.NpiNumber
end as npi
Also as Euric Mentioned you may want to look at your all-lowercase column name.

need to translate specific t-sql case in pl/sql

Can anyone tell me how to translate the following T-SQL statement:
SELECT fileld1 = CASE
WHEN T.option1 THEN -1
ELSE
CASE WHEN T.option2 THEN 0
ELSE 1
END
END
FROM Table1 AS T
The point is I need to validate two different options from the table for a single field in the select statement..
I have tried to do somthing with an IF statement in pl/sql, but it just doesnt work for me:
SELECT IF T.option1 THEN -1
ELSE IF T.option2 THEN 0
ELSE 1
END
FROM Table1 AS T
I am not actually sure how to write IF statement inside the SELECT statement..
And also, I need to do it INSIDE the select statement because I am constructing a view.
Use:
SELECT CASE
WHEN T.option1 = ? THEN -1
WHEN T.option2 = ? THEN 0
ELSE 1
END AS field1
FROM Table1 AS T
I can't get your original TSQL to work - I get:
Msg 4145, Level 15, State 1, Line 4
An expression of non-boolean type specified in a context where a condition is expected, near 'THEN'.
...because there's no value evaluation. If you're checking if the columns are null, you'll need to use:
SELECT CASE
WHEN T.option1 IS NULL THEN -1
WHEN T.option2 IS NULL THEN 0
ELSE 1
END AS field1
FROM Table1 AS T
...or if you need when they are not null:
SELECT CASE
WHEN T.option1 IS NOT NULL THEN -1
WHEN T.option2 IS NOT NULL THEN 0
ELSE 1
END AS field1
FROM Table1 AS T
CASE expressions shortcircuit - if the first WHEN matches, it returns the value & exits handling for that row - so the options afterwards aren't considered.
If I remember correctly, PL/SQL also supports the case. You just would have to move the column alias from "field1=" before the expression to "AS filed1" after the expression.