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

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.

Related

Teradata Case Expression and Text Comparison <> Not Working

I am trying to run a Case expression that will return a value when a field does not equal a specific text value.
Specifically, I am trying to return 'YES' when the field does not equal 'Yes'. The current value is null. I would expect the result to return 'YES' since the value does not equal 'Yes'. The query is returning 'NO'.
The excerpt of my query is listed below. Any help would be greatly appreciated.
SELECT
CASE
WHEN "Renewal"<>'Yes'
THEN 'YES'
ELSE 'NO'
END
FROM "DATABASE"."TABLE"
WHERE "Asset_Id" = '006817'

Fix date issue in a .csv file with utl_file

I am using utl_file to write in a csv file. The data includes date columns also. The issue here is
For a single digit day 0 gets removed when the data gets inserted in the csv file.
Eg - date 07-Jun-13 gets inserted as 7-Jun-13, how can I ensure that 0 stays?
I already to_char and concat "" but still I get single digit date only. The csv file being generated is used by a 3rd party system hence no change can be made in the csv.
I am using EBS 12.1.3.
Thanks
PL/SQL code snippet
concat(concat('"',lv_proj_start_date),'"') ||','||
concat(concat('"',lv_proj_start_date_plus_1),'"') ||','||
I expect the output for date in the csv like 07-Jun-13
but in csv file the o/p is 7-Jun-13.
Assuming both columns are of DATE format, you need to explicitly convert the date into whichever format you desire, e.g.:
'"' || to_char(lv_proj_start_date, 'dd-Mon-yy', 'nls_date_language=english') || '","'
|| to_char(lv_proj_start_date_plus_1, 'dd-Mon-yy', 'nls_date_language=english') || '",'
N.B. I have also converted your CONCAT function calls to use the concatenation operator ||, as this is much easier to read. I've also combined text strings where possible.
I have also used the optional third parameter of to_char() to explicitly set the date language to be English, which makes it NLS independent.
A final note: do you absolutely have to output the dates with 2-digit years? 4-digits are preferred nowawdays, post Y2K!
ETA: Here's an example showing that the output is correct:
DECLARE
lv_proj_start_date DATE := to_date('07/07/2019', 'dd/mm/yyyy');
lv_proj_start_date_plus_1 DATE := lv_proj_start_date + 1;
v_str VARCHAR2(4000);
BEGIN
v_str := '"Testing","' || to_char(lv_proj_start_date, 'dd-Mon-yy', 'nls_date_language=english') || '","'
|| to_char(lv_proj_start_date_plus_1, 'dd-Mon-yy', 'nls_date_language=english') || '"';
dbms_output.put_line(v_str);
END;
/
"Testing","07-Jul-19","08-Jul-19"

Using Case Function to make NULL values appear as blank

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

How can I add a running integer to my current time in sqlite

I have a SQLite DB where in the field Messdatum there is only the date as TEXT. Now I would like
to concat a random time to the field so that the Messdatum results in ISO format with time.
How can I update my SQL DB with one sql command?
My Select to test is:
SELECT strftime('%Y-%m-%d', Messdatum) ||' ' || strftime('%H:%M:%S', CURRENT_TIME)from lipo
but there always the same TIme.
THanks
If you really wanted random times, you could just add a random number of seconds (86400 is the number of seconds in a day):
SELECT datetime(Messdatum, '+' || (abs(random()) % 86400) || ' seconds')
FROM lipo
However, this does not guarantee that the values are unique for each day.
To get unique values, you could use the internal rowid, but this works only if the first and that last row for each day are less than 86400 rows apart, i.e., this can break if you insert additional rows for a specific day much later:
SELECT datetime(Messdatum, '+' || (rowid % 86400) || ' seconds')
FROM lipo
The most reliable (but slowest) way would be to count how many previous rows there are with the same date:
SELECT datetime(Messdatum, '+' || (SELECT COUNT(*)
FROM lipo AS L2
WHERE L2.Messdatum = lipo.Messdatum
AND L2.rowid < lipo.rowid
) || ' seconds')
FROM lipo

How do I add opening and closing brackets to the beginning and end of the data string in Sqlite

I have a column of text in sqlite that I have to select and add brackets to the beginning and end of each string of data. EG. column has "hello" I need to select it, adding brackets so it looks like "(hello)"
I have done this before in Sqlite, but can't remember how I did it. Any ideas would be really appreciated. I am sure it will be pretty simple.
Use || to concatenate strings:
SELECT '(' || 'hello' || ')';
SELECT '(' || column_name || ')' FROM table_name WHERE condition;

Resources