COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Framework Manager => Topic started by: bbrooksux on 10 Mar 2010 04:08:49 PM

Title: Converting ASCII character code in SQL and Oracle
Post by: bbrooksux on 10 Mar 2010 04:08:49 PM
We are working on porting our OEM solution from SQL to Oracle.  Most of the framework elements are dbms agnostic for the most part, however one section of our framework dealing with our custom properties is utilizing a char function that is SQL specific.  Essentially we're using 3 functions -- substring, position and char -- to segment out a multi value field based on the ASCII character code 2.  The SQL used is as follows:
substring(
    [Custom Properties].[IN_PROP].[DISPLAY_FORMAT],
    0,
    position ( char(2), [Custom Properties].[IN_PROP].[DISPLAY_FORMAT] ) )

We would like to find a way to make this more agnostic, if at all possible, and the char function is what is causing the problem in this item.  Does anyone have suggestions on how best to separate out the data?

Here's a sample of the raw data:
currencytrueUSDfixed2

expected output:
currency
Title: Re: Converting ASCII character code in SQL and Oracle
Post by: blom0344 on 11 Mar 2010 09:09:21 AM
Define a database function (1 for oracle, 1 for SQL server) That performs the entire action. Use the same name in both RDBMS. Import the function and use this in a Cognos SQL. Perhaps this will allow you to have one single Cognos object to perform the job on both SQL server / Oracle.
(No idea whether this will work    :-\  )
Title: Re: Converting ASCII character code in SQL and Oracle
Post by: bbrooksux on 11 Mar 2010 03:39:46 PM
Can you give an example of how to create the database function?  That seems like a great solution, but getting over that first hump seems like the big obstacle right now.   Thanks!
Title: Re: Converting ASCII character code in SQL and Oracle
Post by: blom0344 on 12 Mar 2010 02:24:57 AM
T-SQL example:



CREATE FUNCTION [dbo].[BBROOKSSUX]
(
@tableprimkey varchar(50)
)
RETURNS varchar(200)
AS
BEGIN
DECLARE @locale varchar(200)

set @locale = substring( DISPLAY_FORMAT, 0,position ( char(2), DISPLAY_FORMAT) )
from CUSTOMTABLE where PRIMKEY = @tableprimkey
)
RETURN (@locale)

END



Assuming that the CUSTOMTABLE in the database has a primary key (in my example a string, would probably be an integer) you can reference in the function to get 1 result from the function call.
Title: Re: Converting ASCII character code in SQL and Oracle
Post by: blom0344 on 30 Mar 2010 09:01:09 AM
Just out of curiousity.. Did you manage to accomplish your goal?