Using Case Function to make NULL values appear as blank - cognos-10

I keep getting error that my Case Function is incorrect. My goal is to use the Case Function to make every NULL or '0' values appear as blank. Incompatible data types in case statement is the prompt that I get when running it in report studio. Example of the table would be this. WCPDOD is an Integer, WCPDOD 9int,null)
WCPDOD POLICY CLAIM NUMBER
19741020 2001A 123456N000040
20040101 2003A 456789001531
20021220 00594 123456
20040507 2003A 2222043621
20040517 2003I 90043625
CASE
WHEN [WCPDOD] = '0' THEN ' '
WHEN [WCPDOD] IS NULL THEN ' '
ELSE [WCPDOD]
END

Since WCPDOD is an integer, you shouldn't compare it to string literals such as '0', but to numeric literals, such as 0. More importantly, different branches of your case statement return different types - the first two return strings (the ' ' literal) and the else branch returns an integer. You should cast it to a string:
CASE
WHEN [WCPDOD] = 0 THEN ' '
WHEN [WCPDOD] IS NULL THEN ' '
ELSE CAST ([WCPDOD] AS VARCHAR(40))
END

Related

Not able to concatenate Values Based on Different columns in case when statement -Snowflake

Hope are you doing well!..I am trying to concatenate values of case when statement based on different columns in snowflake ..Please find the block of code below
select *,
case when checkouttime is null then ',Patient is not checked out' else '' END
+ case when primarypatientinsuranceid is null then ',No insurance information' else '' END
+ case when closedby is null then ',Encounter not signed off' else '' END
+ case when billingtabcheckeddate is null then ',Billing tab is not checked' else ''
+ case when alreadyrouted is null then ',Missing slip already routed' else 'Valid Missing slip'
END as resultant
from final
I am getting the error saying " Unexpected as"
I am trying to build the resultant column output as the following
Patient is not checked out/Billing tab is not checked
Missing slip already routed
Encounter not signed off/No insurance information /Billing tab is not checked
Valid Missing slip
Thanks,
Arun
A cleaner alternative that adds commas as necessary, using array_to_string(array_construct_compact()):
with data as (
select null checkouttime
, 2 primarypatientinsuranceid
, null closedby
, 4 billingtabcheckeddate
, 5 alreadyrouted
)
select array_to_string(array_construct_compact(
iff(checkouttime is null, 'Patient is not checked out', null)
, iff(primarypatientinsuranceid is null, 'No insurance information', null)
, iff(closedby is null, 'Encounter not signed off', null)
, iff(billingtabcheckeddate is null, 'Billing tab is not checked', null)
, iff(alreadyrouted is null, 'Missing slip already routed', 'Valid Missing slip')
), ', ')
as resultant
from data
In Snowflake, you use "||" to concat strings, not "+":
select
case when true then ',Patient is not checked out' else '' END
|| case when false then ',No insurance information' else '' END
|| case when true then ',Encounter not signed off' else '' END
|| case when true then ',Billing tab is not checked' else '' END
|| case when false then ',Missing slip already routed' else 'Valid Missing slip' END
as resultant;
https://docs.snowflake.com/en/sql-reference/functions/concat.html

How can I remove the commas from a multi-select parameter in Cognos 10 Report Studio?

I started with a text prompt where a user can enter a string representing days in a single week. For example, M = Monday, and MWF can be typed in to choose Monday, Wednesday, and Friday.
I've just changed the prompt to a multi-select value prompt, and modified my filters to work correctly. Now my prompt looks like this:
When the user selects the items Monday, Wednesday, Friday, the ParamValue list is M,W,F.
How can I display MWF as a data item?
Specifically, I want to combine the new day(s) with a time selected so I can get an output result of MWF 0800 - 1100 but the time values are already taken care of.
Can I somehow index the values inside the multi-select value?
Edit:
I should also mention that variations on
?p_NewDays? || ' ' || ?p_NewStartTime? || '-' || ?p_NewEndTime?
don't seem to work, it will only list the first item in the selection. And TO_CHAR only works for dates.
You can accomplish this with a vendor provided replace() function replacing each comma with an empty string. However, the implementation of such function varies from vendor to vendor. For a vendor-neutral solution you can use this expression to do the same thing:
CASE
WHEN 'M' in ?param? THEN 'M'
ELSE ''
END
||
CASE
WHEN 'T' in ?param? THEN 'T'
ELSE ''
END
||
CASE
WHEN 'W' in ?param? THEN 'W'
ELSE ''
END
||
CASE
WHEN 'Th' in ?param? THEN 'Th'
ELSE ''
END
||
CASE
WHEN 'F' in ?param? THEN 'F'
ELSE ''
END
||
CASE
WHEN 'S' in ?param? THEN 'S'
ELSE ''
END
||
CASE
WHEN 'Su' in ?param? THEN 'Su'
ELSE ''
END
I used the generic ?param? for the parameter name. You would have to change it to match your specific parameter.
You didn't indicate how you differentiate between Tuesday and Thursday as well as Saturday and Sunday. I simply used the first initial for the first day of the week to start with that letter and used a common two-letter abbreviation for the second instance.

PLS-00103: Encountered the symbol "/"

I am aware that this has been asked so many times, but my problem doesn't seem to go away. I've already put the delimiter in the correct places but i still keep on getting error 'Error(9,1): Encountered the symbol "/" ' at line 9. If I'm not mistaken, the delimiter that causes the error shold be there.
CREATE OR REPLACE PACKAGE FOR_CLASS_NOV2 AS
PROCEDURE PRINT_SNAME(S_NO S.SNO%TYPE);
FUNCTION FIND_MAX_QTY
RETURN NUMBER;
END;
/
CREATE OR REPLACE PACKAGE BODY FOR_CLASS_NOV2 AS
PROCEDURE PRINT_SNAME(S_NO S.SNO%TYPE) IS
S_SNAME S.SNAME%TYPE;
BEGIN
SELECT SNAME
INTO S_SNAME
FROM S
WHERE SNO = S_NO;
DBMS_OUT.PUT_LINE('SUPPLIER NAME IS: ' || S_NAME);
END PRINT_SNAME;
FUNCTION FIND_MAX_QTY()
RETURN NUMBER IS
M_QTY NUMBER;
BEGIN
SELECT AX(STY)
INTO M_QTY
FROM SP;
RETURN M_QTY;
END FIND_MAX_QTY;
END;
/
I think you should not use parenthesis in the function when there's no parameters.
Try replacing this:
FUNCTION FIND_MAX_QTY()
RETURN NUMBER IS
With this:
FUNCTION FIND_MAX_QTY
RETURN NUMBER IS
Also, you have a variable named S_SNAME but you're printing S_NAME.

PL-SQL bind variables in TCL

Could some one explain in the following TCL source code:
set sql "SELECT PROD.KEY || ' {' || PARAMETERS || '}' \
FROM PRV_PROD_MAPPING PROD \
WHERE PROD.SERVICE_ID = :service_id \
AND (PROD.KEY || ' ' || PROD.KEY_VAL) \
IN (:keys) "
what :service_id and :keys mean. Could I see the values behind by simple trace.
How could I find where these vars are defined?
Thanks in advance!
It's not TCL its an SQL query embedded in a TCL string, specifically one that binds a variable, which is then assigned to a normal TCL variable
As glenn points out, on its own this snippet of TCL does very little. presuembly somewhere in your program you actually connect to a DB and pass it a query from this string and some other variables
If you're using TDBC, you might have
# assume the connection has already occured and is named "db"
set sql "SELECT ... WHERE a.b=:service_id IN (:keys)"
set statement [db prepare $sql]
# get the bind variables' values from the local context:
set service_id 42
set keys [join {key1 key2 key3} ,]
set resultset [$statement execute]
# or, without setting the "service_id" and "keys" variables,
# provide them as an argument to the execute subcommand
unset service_id keys
set resultset [$statement execute {service_id 24 keys "foo,bar,baz"}]
As others pointed out it you just assign a string* to a variable.
More exactly, you assign the following string to a variable called sql
SELECT PROD.KEY || ' {' || PARAMETERS || '}' FROM PRV_PROD_MAPPING PROD WHERE PROD.SERVICE_ID = :service_id AND (PROD.KEY || ' ' || PROD.KEY_VAL) IN (:keys)
The values of :service_id and :keys are bound values that are passed later (In a oraplexec statement probably).
|| is string concatenation in SQL. So PROD.KEY || ' {' || PARAMETERS || '}' could be PRODKEY {PARAMETERS}.
*Everything is a string
I've done it using traces:
sys.DBMS_SYSTEM.SET_EV(n_sid, n_serial, 10046, 12, '');
DBMS_OUTPUT.put_line('Trace started: ' || to_char(SYSDATE,'dd.mm.yyyy hh24:mi:ss'));

ASP.NET Error with session key strings

Hey I am trying to convert the following code to VB.NET from this webpage
http://msdn.microsoft.com/en-us/magazine/cc163730.aspx
And have a method converted as such
' Get the order from the session on demand
Private Shared Function GetOrderFromSession(ByVal i As Integer) As ShoppingCartOrder
Dim session As HttpSessionState = HttpContext.Current.Session
Dim ID As Integer = 0
Dim quantity As Integer = 0
' note: For simplicity session key strings are dynamically
' created——for performance reasons they should be precreated.
ID = CInt(session(ShoppingCartItemIDKeyBase + i))
quantity = CInt(session(ShoppingCartOrderQuantityKeyBase + i))
Dim item As ShoppingCartItem = ShoppingCartItem.GetItem(ID)
Return New ShoppingCartOrder(item, quantity)
End Function
But getting the error around the lines
ID = CInt(session(ShoppingCartItemIDKeyBase + i))
quantity = CInt(session(ShoppingCartOrderQuantityKeyBase + i))
Error 1 Overload resolution failed because no accessible 'Item' can be called without a narrowing conversion:
'Public Default Property Item(index As Integer) As Object': Argument matching parameter 'index' narrows from 'Double' to 'Integer'.
'Public Default Property Item(name As String) As Object': Argument matching parameter 'name' narrows from 'Double' to 'String'.
The + operator can be used for string concatenation as well as the & operator in VB.NET, but the ampersand is the preferred operator.
Just to be sure, can you switch them to ampersands and see if the error still occurs? ShoppingCarItemIDKeyBase is a string, and I'm not sure if the + operator forces the strings to convert to numbers since the user has the option of using &.
ID = CInt(session(ShoppingCartItemIDKeyBase & i))
quantity = CInt(session(ShoppingCartOrderQuantityKeyBase & i))
One or both of these variables is a decimal type rather than an integer:
ShoppingCartItemIDKeyBase
ShoppingCartOrderQuantityKeyBase

Resources