SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Convert comma seperated list into one column (Cognos)


Convert comma seperated list into one column (Cognos)

Author
Message
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)

Group: General Forum Members
Points: 31814 Visits: 18550
savedanthony (8/4/2011)
It's just hard to find someone with the knowledge in both systems. But thank you both for trying.


Sorry we couldn't help more.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Darren Wallace
Darren Wallace
Old Hand
Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)Old Hand (326 reputation)

Group: General Forum Members
Points: 326 Visits: 1459
savedanthony (7/28/2011)
I am trying to use SQL to transfer a prompt list of values into a column that I can join with values in a cognos table in order to have a full report rather then needing to do external work in excel or somewhere outside of cognos. Here's what I have so far for my sql:

select
(#prompt('List', 'String')#) as Data_Item1,
(#sq(csv( split(', ', prompt('List', 'token') ) ))#) as Data_Item4
from
MAXIMO_DW..MAXIMOCGNS.ASSET C__wo__ASSET
where
(C__wo__ASSET.ASSETNUM = 'LC061808' or C__wo__ASSET.ASSETNUM = 'MA3004')

This will bring back the prompted value as one entry as entered (data_item1) or with extra single quotes on each entry (Data_item4). Now I have seen functions that will do what I want, but I don't know how to integrate them into this setup. The purpose for this setup is it atleast passes and gives me an outcome. The other functions I have tried only give me an error that I can't figure out. So, any help would be greatly appreciated. Thanks


The way I've done something similar to this (note I have Cognos 8.4 and SQL Server so you may have to change the code to work in ORACLE) is:
1) Create a table valued function (TVF) in SQL Server that accepts a comma separated string and parses it out to a table. There are many good ways to do this (see the Tally Table option presented previously) but I've used the attached funtion -ufn_Split.txt. It's not perfect or robust but works well for the limited set of circumstances I use it for (no embedded commas in the data and a not terribly large data set) and it's obvious enough that if I'm hit by a bus I don't worry much.
2) Create a Query Subject in Framework Manager. Pass the cognos macro value (#macro stuff#) into the TVF and get back the table.
SELECT *
FROM dbo.ufn_Split (#CSVIdentityNameList(',')#)


This really belongs in a Cognos forum since the complexity is all in Cognos and it's macro handling oddities rather than SQL Server but since I was here...

-Darren Wallace
Attachments
ufn_Split.txt (14 views, 1,011 bytes)
SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)

Group: General Forum Members
Points: 31814 Visits: 18550
Darren Wallace (8/5/2011)
savedanthony (7/28/2011)
I am trying to use SQL to transfer a prompt list of values into a column that I can join with values in a cognos table in order to have a full report rather then needing to do external work in excel or somewhere outside of cognos. Here's what I have so far for my sql:

select
(#prompt('List', 'String')#) as Data_Item1,
(#sq(csv( split(', ', prompt('List', 'token') ) ))#) as Data_Item4
from
MAXIMO_DW..MAXIMOCGNS.ASSET C__wo__ASSET
where
(C__wo__ASSET.ASSETNUM = 'LC061808' or C__wo__ASSET.ASSETNUM = 'MA3004')

This will bring back the prompted value as one entry as entered (data_item1) or with extra single quotes on each entry (Data_item4). Now I have seen functions that will do what I want, but I don't know how to integrate them into this setup. The purpose for this setup is it atleast passes and gives me an outcome. The other functions I have tried only give me an error that I can't figure out. So, any help would be greatly appreciated. Thanks


The way I've done something similar to this (note I have Cognos 8.4 and SQL Server so you may have to change the code to work in ORACLE) is:
1) Create a table valued function (TVF) in SQL Server that accepts a comma separated string and parses it out to a table. There are many good ways to do this (see the Tally Table option presented previously) but I've used the attached funtion -ufn_Split.txt. It's not perfect or robust but works well for the limited set of circumstances I use it for (no embedded commas in the data and a not terribly large data set) and it's obvious enough that if I'm hit by a bus I don't worry much.
2) Create a Query Subject in Framework Manager. Pass the cognos macro value (#macro stuff#) into the TVF and get back the table.
SELECT *
FROM dbo.ufn_Split (#CSVIdentityNameList(',')#)


This really belongs in a Cognos forum since the complexity is all in Cognos and it's macro handling oddities rather than SQL Server but since I was here...

-Darren Wallace


Thanks for chipping in.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

savedanthony
savedanthony
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 34
Hey, I did find a couple of steps from some coworkers. Basically I found that I could use the format:

SELECT (substr(#prompt('List', 'String')#,1,instr(#prompt('List','String')#,', ')-1)) Asset FROM Dual Union
SELECT (upper(#prompt('List', 'String')#) || ', ') Asset FROM Dual Union
SELECT 'Last' Asset FROM Dual

and basically add as many things as I want as long as the last option doesn't have union on it. So, the next part I am confused on is how to use an if then or case statement to decide what to select. For example the code above works, now ideally I would like to use:

if #prompt('Choice','String')# = 'Yes'
then
SELECT (substr(#prompt('List', 'String')#,1,instr(#prompt('List','String')#,', ')-1)) Asset FROM Dual Union
SELECT (upper(#prompt('List', 'String')#) || 'Test') Asset FROM Dual Union
SELECT 'It worked' Asset FROM Dual
else
SELECT (substr(#prompt('List', 'String')#,1,instr(#prompt('List','String')#,', ')-1)) Asset FROM Dual Union
SELECT (upper(#prompt('List', 'String')#) || 'Test') Asset FROM Dual Union
SELECT 'Some Text Data2' Asset FROM Dual end

I don't know the syntex for using the if then test to decide what to select though.
savedanthony
savedanthony
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 34
basically the logic of this code is what I need into the format of an sql select query:

declare @start as int;
declare @end as int;
declare @entries as int;

set @start = 1;

set @entries = (length(#prompt('List','String')#) - length(replace(#prompt('List','String')#, ',')))+1;

for i = 1 to @entries

@end = instr(#prompt('List','String')#,', ',@start)-1;

if i = @entries

then
SELECT (substr(#prompt('List', 'String')#,@start,@end)) Asset FROM Dual

else
SELECT (substr(#prompt('List', 'String')#,@start,@end)) Asset FROM Dual union

end

@start = @end + 2;

next
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search