Output as a single row with values separated by comas
I have a query that returns one column as:
Col1
a
b
c
I want the output as a single row with values separated by comas:
Col1
a,b,c
How do I do it in SQL?
Or... build your own aggregation function :
SQL> create or replace type AggregateStr as object
2 (
3 tag VARCHAR2(1),
4 str VARCHAR2(4000), -- concatenation string
5 static function ODCIAggregateInitialize(sctx IN OUT AggregateStr) return number,
6 member function ODCIAggregateIterate(self IN OUT AggregateStr, value IN VARCHAR2) return number,
7 member function ODCIAggregateTerminate(self IN AggregateStr, returnValue OUT VARCHAR2, flags IN number) return number,
8 member function ODCIAggregateMerge(self IN OUT AggregateStr, ctx2 IN AggregateStr) return number
9 );
10 /
Type created.
Elapsed: 00:00:00.00
SQL>
SQL> create or replace type body AggregateStr is
2 static function ODCIAggregateInitialize(sctx IN OUT AggregateStr) return number is
3 begin
4 sctx := AggregateStr(',','');
5 return ODCIConst.Success;
6 end;
7
8 member function ODCIAggregateIterate(self IN OUT AggregateStr, value IN VARCHAR2) return number is
9 begin
10 self.str:=self.str||value||self.tag;
11 return ODCIConst.Success;
12 end;
13
14 member function ODCIAggregateTerminate(self IN AggregateStr, returnValue OUT VARCHAR2, flags IN number) return number is
15 begin
16 returnValue := rtrim(self.str,',');
17 return ODCIConst.Success;
18 end;
19
20 member function ODCIAggregateMerge(self IN OUT AggregateStr, ctx2 IN AggregateStr) return number is
21 begin
22 self.str := ctx2.str;
23 return ODCIConst.Success;
24 end;
25 end;
26 /
Type body created.
Elapsed: 00:00:00.00
SQL>
SQL> CREATE OR REPLACE FUNCTION ConcateStr (input VARCHAR2) RETURN VARCHAR2
2 PARALLEL_ENABLE AGGREGATE USING AggregateStr;
3 /
Function created.
Elapsed: 00:00:00.00
SQL>
SQL> select max(concate_string) keep (dense_rank last order by length(concate_string)) as concate_string
2 from (select ConcateStr(ename) over (order by ename) concate_string
3 from emp);
CONCATE_STRING
ADAMS,ALLEN,BLAKE,CLARK,FORD,JAMES,JONES,KING,MARTIN,MILLER,SCOTT,SMITH,TURNER,WARD
Elapsed: 00:00:00.00Or if you doesn't matter of the order :
SQL> select ConcateStr(ename)
2 from emp;
CONCATESTR(ENAME)
SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLERNicolas.
adding the second query.
Message was edited by:
N. Gasparotto
Similar Messages
-
How can i get all these values in single row with comma separated?
I have a table "abxx" with column "absg" Number(3)
which is having following rows
absg
1
3
56
232
43
436
23
677
545
367
xxxxxx No of rows
How can i get all these values in single row with comma separated?
Like
output_absg
1,3,56,232,43,436,23,677,545,367,..,..,...............
Can you send the query Plz!These all will do the same
create or replace type string_agg_type as object
2 (
3 total varchar2(4000),
4
5 static function
6 ODCIAggregateInitialize(sctx IN OUT string_agg_type )
7 return number,
8
9 member function
10 ODCIAggregateIterate(self IN OUT string_agg_type ,
11 value IN varchar2 )
12 return number,
13
14 member function
15 ODCIAggregateTerminate(self IN string_agg_type,
16 returnValue OUT varchar2,
17 flags IN number)
18 return number,
19
20 member function
21 ODCIAggregateMerge(self IN OUT string_agg_type,
22 ctx2 IN string_agg_type)
23 return number
24 );
25 /
create or replace type body string_agg_type
2 is
3
4 static function ODCIAggregateInitialize(sctx IN OUT string_agg_type)
5 return number
6 is
7 begin
8 sctx := string_agg_type( null );
9 return ODCIConst.Success;
10 end;
11
12 member function ODCIAggregateIterate(self IN OUT string_agg_type,
13 value IN varchar2 )
14 return number
15 is
16 begin
17 self.total := self.total || ',' || value;
18 return ODCIConst.Success;
19 end;
20
21 member function ODCIAggregateTerminate(self IN string_agg_type,
22 returnValue OUT varchar2,
23 flags IN number)
24 return number
25 is
26 begin
27 returnValue := ltrim(self.total,',');
28 return ODCIConst.Success;
29 end;
30
31 member function ODCIAggregateMerge(self IN OUT string_agg_type,
32 ctx2 IN string_agg_type)
33 return number
34 is
35 begin
36 self.total := self.total || ctx2.total;
37 return ODCIConst.Success;
38 end;
39
40
41 end;
42 /
Type body created.
[email protected]>
[email protected]> CREATE or replace
2 FUNCTION stragg(input varchar2 )
3 RETURN varchar2
4 PARALLEL_ENABLE AGGREGATE USING string_agg_type;
5 /
CREATE OR REPLACE FUNCTION get_employees (p_deptno in emp.deptno%TYPE)
RETURN VARCHAR2
IS
l_text VARCHAR2(32767) := NULL;
BEGIN
FOR cur_rec IN (SELECT ename FROM emp WHERE deptno = p_deptno) LOOP
l_text := l_text || ',' || cur_rec.ename;
END LOOP;
RETURN LTRIM(l_text, ',');
END;
SHOW ERRORS
The function can then be incorporated into a query as follows.
COLUMN employees FORMAT A50
SELECT deptno,
get_employees(deptno) AS employees
FROM emp
GROUP by deptno;
###########################################3
SELECT SUBSTR(STR,2) FROM
(SELECT SYS_CONNECT_BY_PATH(n,',')
STR ,LENGTH(SYS_CONNECT_BY_PATH(n,',')) LN
FROM
SELECT N,rownum rn from t )
CONNECT BY rn = PRIOR RN+1
ORDER BY LN desc )
WHERE ROWNUM=1
declare
str varchar2(32767);
begin
for i in (select sal from emp) loop
str:= str || i.sal ||',' ;
end loop;
dbms_output.put_line(str);
end;
COLUMN employees FORMAT A50
SELECT e.deptno,
get_employees(e.deptno) AS employees
FROM (SELECT DISTINCT deptno
FROM emp) e;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 SMITH,JONES,SCOTT,ADAMS,FORD
30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
CREATE OR REPLACE FUNCTION concatenate_list (p_cursor IN SYS_REFCURSOR)
RETURN VARCHAR2
IS
l_return VARCHAR2(32767);
l_temp VARCHAR2(32767);
BEGIN
LOOP
FETCH p_cursor
INTO l_temp;
EXIT WHEN p_cursor%NOTFOUND;
l_return := l_return || ',' || l_temp;
END LOOP;
RETURN LTRIM(l_return, ',');
END;
COLUMN employees FORMAT A50
SELECT e1.deptno,
concatenate_list(CURSOR(SELECT e2.ename FROM emp e2 WHERE e2.deptno = e1.deptno)) employees
FROM emp e1
GROUP BY e1.deptno;
DEPTNO EMPLOYEES
10 CLARK,KING,MILLER
20 SMITH,JONES,SCOTT,ADAMS,FORD
30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
CREATE OR REPLACE TYPE t_string_agg AS OBJECT
g_string VARCHAR2(32767),
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER,
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER
SHOW ERRORS
CREATE OR REPLACE TYPE BODY t_string_agg IS
STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
RETURN NUMBER IS
BEGIN
sctx := t_string_agg(NULL);
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
value IN VARCHAR2 )
RETURN NUMBER IS
BEGIN
SELF.g_string := self.g_string || ',' || value;
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
returnValue OUT VARCHAR2,
flags IN NUMBER)
RETURN NUMBER IS
BEGIN
returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
RETURN ODCIConst.Success;
END;
MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
ctx2 IN t_string_agg)
RETURN NUMBER IS
BEGIN
SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
RETURN ODCIConst.Success;
END;
END;
SHOW ERRORS
CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
RETURN VARCHAR2
PARALLEL_ENABLE AGGREGATE USING t_string_agg;
/ -
Need a query to merge output in a single row?
Hi All,
I need a query to merge output in a single row.
Query :
Select dname from dept.
Actual output is :
Dname
EDP
ACCOUNT
GR
Desired Output is:
Dname
EDP ACCOUNT GR
Please provide me the solution
Thanks
Amitselect max(sys_connect_by_path (t.name,' ')) from ( select id,
name,
group_id,
row_number() over (partition by group_id order by id) rn
from ( select 1 id, 'test' name, 1 group_id from dual
union
select 2 id, 'test1' name, 1 group_id from dual
union
select 3 id, 'test2' name, 1 group_id from dual
union
select 4 id, 'test3' name, 1 group_id from dual) ) t
start with t.rn = 1 and id = 1
connect by t.rn = prior t.rn + 1
group by t.group_id -
Combining Multiple Rows into single row with multple columns
Hi Experts,
I have the following requirement, kindly help me.
I have data in my table like below.
ID NAME DEPT
1 Sam 10
1 Sam 20
2 alex 30
2 alex 40
2 alex 50
3 vinod 60
3 vinod 70
I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.
ID NAME DEPT1 DEPT2 DEPT3
1 Sam 10 20
2 alex 30 40 50
3 vinod 60 70
It's urgent requirement, kindly help me.
Thanks in advance.Right I've had my drink, so what was this "urgent" question then?
798616 wrote:
I have data in my table like below.
ID NAME DEPT
1 Sam 10
1 Sam 20
2 alex 30
2 alex 40
2 alex 50
3 vinod 60
3 vinod 70
I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.Dynamic numbers of columns eh! Tricky.
If you understand how SQL statements are executed it's along these lines...
1. Open Cursor
2. Parse SQL statement and determine columns
3. Bind in any input values
4. Fetch data
5. Bind out values to columns
6. Repeat step 3 until no more data
7. Close cursor
Now, you're expecting that you can determine the columns (step 2) from the fetched data (step 4 onwards). You can't. The SQL engine needs to know the expected columns before any data is fetched so, it can't base the number of columns on the data itself.
If you need that requirement, you would need to query the data first and build up a dynamic query based on the data and then execute that dynamically built query to fetch the data and pivot it into those columns, which means that you have queried the data twice. Not good practice and not good (or simple) coding.
What you're talking of doing is something that should be handled at the presentation/interface layer, not as part of the data fetch.
Typically these sorts of things are handled most easily in report generation/writer tools such as Oracle Reports, Business Objects etc. where they fetch the data from the database and then process it to format it on the display, pivoting the results as required.
It's not something that lends itself to be easily achieved in SQL. Yes, SQL can do pivoting of data quite easily, but NOT with a dynamic number of columns.
If you were to specify that there is a maximum number of columns that you could get (rather than wanting it dynamic), then you can do it simply in SQL with the max-decode method...
SQL> ed
Wrote file afiedt.buf
1 with t as (select deptno, ename, row_number() over (partition by deptno order by ename) as rn from emp)
2 --
3 select deptno
4 ,max(decode(rn,1,ename)) as ename1
5 ,max(decode(rn,2,ename)) as ename2
6 ,max(decode(rn,3,ename)) as ename3
7 ,max(decode(rn,4,ename)) as ename4
8 ,max(decode(rn,5,ename)) as ename5
9 ,max(decode(rn,6,ename)) as ename6
10 ,max(decode(rn,7,ename)) as ename7
11 ,max(decode(rn,8,ename)) as ename8
12 ,max(decode(rn,9,ename)) as ename9
13 ,max(decode(rn,10,ename)) as ename10
14 from t
15 group by deptno
16* order by deptno
SQL> /
DEPTNO ENAME1 ENAME2 ENAME3 ENAME4 ENAME5 ENAME6 ENAME7 ENAME8 ENAME9 ENAME10
10 CLARK KING MILLER
20 ADAMS FORD JONES SCOTT SMITH
30 ALLEN BLAKE JAMES MARTIN TURNER WARD
SQL> -
SQL - Multiple Fetch into Single Column with Comma Separator
Hello Experts,
Good Day to all...
I need your help on following scenarios. The below query returns set of titleID strings. Instead of printing them one below the other as query output, I want the output to be in batch of 25 values.i.e each row should have 25 values separated by comma. i.e If there are 100 titles satisfying the output, then there should be only four rows with and each row having 25 titles in comma separated manner.
SELECT DISTINCT title_id
FROM pack_relation
WHERE package_id IN ( SELECT DISTINCT fa.package_id
FROM annotation fa
GROUP BY fa.package_id
HAVING COUNT
(fa.package_id) <100);I tried with the PL/SQL block; whereas it is printing all the values continously :(
I need to stop with 25 values and display.
If its possible with SQL block alone; then it would be of great help
DECLARE
v_str VARCHAR2 (32767) := NULL;
CURSOR c1
IS
SELECT DISTINCT title_id
FROM pack_relation
WHERE package_id IN ( SELECT DISTINCT fa.package_id
FROM annotation fa
GROUP BY fa.package_id
HAVING COUNT
(fa.package_id) <100);
BEGIN
FOR i IN c1
LOOP
v_str := v_str || ',' || i.title_id;
END LOOP;
v_str := SUBSTR (v_str, 2);
DBMS_OUTPUT.put_line (v_str);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Error-->' || SQLERRM);
END;Thanks...You can use CEIL
Sample code
SELECT
nt,
LTRIM(MAX(SYS_CONNECT_BY_PATH(val,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concat_val
FROM
SELECT
val,
nt,
ROW_NUMBER() OVER (PARTITION BY nt ORDER BY val) AS curr,
ROW_NUMBER() OVER (PARTITION BY nt ORDER BY val) -1 AS prev
FROM
SELECT
level AS val,
ceil(rownum/3) as nt /* Grouped in batches of 3 */
FROM
dual
CONNECT BY level <= 10
GROUP BY
nt
CONNECT BY prev = PRIOR curr
AND nt = PRIOR nt
START WITH curr = 1;
NT CONCAT_VAL
1 1,2,3
2 4,5,6
3 7,8,9
4 10Your code
SELECT
nt,
LTRIM(MAX(SYS_CONNECT_BY_PATH(title_id,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concat_val
FROM
SELECT
title_id,
nt,
ROW_NUMBER () OVER (PARTITion BY nt ORDER BY title_id) AS curr,
ROW_NUMBER() OVER (PARTITION BY nt ORDER BY title_id) -1 AS prev
FROM
SELECT
title_id,
ceil(rownum/25) AS nt /* Grouped in batches of 25 */
FROM
pack_relation tdpr
JOIN annotation fa
ON
tdpr.package_id = fa.package_id
GROUP BY
title_id,
fa.package_id
HAVING
COUNT (fa.package_id) < 500
GROUP BY
nt
CONNECT BY prev = PRIOR curr
AND nt = PRIOR nt
START WITH curr = 1; -
Merge 2 rows into single row with data update?
hello all,
i have a table with below data,
declare @tbl table (uid int, uname varchar(10), start_dt date, end_dt date)
insert into @tbl values (1, 'env1', '4/4/2010', '5/5/2012')
insert into @tbl values (2, 'env2', '5/4/2010', '6/6/2012')
--earlier start data is '4/4/2010' from 'env1'
--latest end data is '6/6/2012' from 'env2'
insert into @tbl values (3, 'env1', '3/3/2010', '4/4/2012')
insert into @tbl values (4, 'env2', '2/2/2010', '5/5/2012')
--earlier start data is '2/2/2010' from 'env2'
--latest end data is '5/5/2012' from 'env2'
insert into @tbl values (5, 'env1', '8/8/2010', '12/12/2012')
insert into @tbl values (6, 'env2', '9/9/2010', '10/10/2012')
--earlier start data is '8/8/2010' from 'env1'
--latest end data is '12/12/2012' from 'env1'insert into @tbl values (6, 'envX', '9/9/2010', '10/10/2012')insert into @tbl values (6, 'envY', '9/9/2010', '10/10/2012')
i need to merge 2 rows for column "uname" having value "env1" & "env2" to "envZ" and need to capture earlier start date and latest end date from both and update with new.
the desire output should be,
declare @tbl table (uid int, uname varchar(10), start_dt date, end_dt date)
insert into @tbl values (1, 'envZ', '4/4/2010', '6/6/2012')
insert into @tbl values (4, 'envZ', '2/2/2010', '5/5/2012')
insert into @tbl values (5, 'envZ', '8/8/2010', '12/12/2012')
insert into @tbl values (6, 'envX', '9/9/2010', '10/10/2012')
insert into @tbl values (6, 'envY', '9/9/2010', '10/10/2012')
note - i must need to update one row and delete other row as i can't insert new rows (having huge data with other columns also).
please suggest optimize query. thanks!Which version and edition of SQL Server are you using?
Whenever there is a row with 'env1', there is a corresponding 'env2' and vice versa?
The row with 'env2' is always after the row with 'env1'? (uid+1)
If the answers are yes to both questions above, here's a possibility:
-- code #1 v3
;with
ENVZ as (
SELECT uid= case when T1.start_dt <= T2.start_dt then T1.uid else T2.uid end,
start_dt= case when T1.start_dt <= T2.start_dt then T1.start_dt else T2.start_dt end,
end_dt= case when T1.end_dt > T2.end_dt then T1.end_dt else T2.end_dt end
from @tbl as T1
inner join @tbl as T2 on T2.uid=T1.uid+1 and T2.uname='env2'
where T1.uname = 'env1'
MERGE
into @tbl as T3
using ENVZ as T4
on T3.uid = T4.uid
when matched and (T3.uname in ('env1','env2')) then
UPDATE set T3.uname= 'envZ',
T3.start_dt= T4.start_dt,
T3.end_dt= T4.end_dt
when not matched by source and (T3.uname in ('env1','env2')) then
DELETE;
The table @tbl is read three times in the above code. There are probably ways to optimize the above code. Or even other more efficient approach.
José Diz Belo Horizonte, MG - Brasil -
How can we display 2 rows in a single row with new coulmn names?
Hi,
I have a requiment as shown below.
ME A_END Z_END
1 aaaa
2 zzzzz
I need the above data in the below format.
A_ME Z_ME A_END Z_END
1 2 aaaa zzzzz
How can we achive this?user6755466 wrote:
Hi Alex,
Thanks for your quick response.
Actually the coulmns ME_ID, A-END, Z-END, etc doesn't have fixed values as you hard coded with values (e.g., 1, 2) in your query.One way is to assign a "row number" to each row and then pivot using the known row numbers of 1, 2 ... etc.
Example:
SQL> ed
Wrote file afiedt.buf
1 with test as
2 (
3 select 3 a_end, 'aaaa ' z_end from dual union all
4 select 5 a_end, 'zzzzz' z_end from dual
5 )
6 select max (decode (rn, 1, a_end)) a_me
7 , max (decode (rn, 2, a_end)) z_me
8 , max (decode (rn, 1, z_end)) a_end
9 , max (decode (rn, 2, z_end)) z_end
10 from (select a_end, z_end
11 ,row_number() over (order by a_end, z_end) as rn
12* from test)
SQL> /
A_ME Z_ME A_END Z_END
3 5 aaaa zzzzz
SQL>Here, the values are 3 and 5, but they are assigned a row number based on the order of them and then the decode uses that row number to pivot them.
Of course, as everyone else has pointed out, the best place to be doing this is in a dedicated reporting tool. SQL is not the best of places to pivot data for reporting purposes. -
How do I make a single row with 6-8 images in css?
I would like to make a header row with 6-8 icons of different dimensions and use them as links. I am having trouble getting them to align horizontally in a container. How do I do this?
You can do it by making the area around the icons the same size. i.e., all images become the same dimension it's just the icons within the image that are different sizes.
If you don't want to do that then probably a good reason to use a table with 6/8 cells otherwise you'll have to set individual padding/margin on each icon to get them to align correctly, doable but a bit long-winded. -
Displaying data from a list into a single field with comma separated values
Hi,
I have a requirement to change a report with an XML structure (simplified version) as below
<Protocol>
<ProtocolNumber>100</ProtocolNumber>
<SiteName>Baxter Building</SiteName>
<ListOfActivity>
<Activity>
<Description>Communication Memo Description.</Description>
<Name>James</Name>
</Activity>
<Activity>
<Description>Visit 4</Description>
<Name>James</Name>
</Activity>
<ListOfActivity/>
</Protocol>
On the report I need to display all the 'Names' for each of the Child (Activities) in a single field at the Parent (Protocol) level, with each Name separated by a comma.
How do I go about getting this to work?
ThanksTake a look at this: http://blogs.oracle.com/xmlpublisher/entry/inline_grouping
You could do this (ofcourse, you will need to add extra logic to ensure that there is no comma added after the last name..)
<?for-each@inlines:Name?><?.?><?', '?><?end for-each?>
Thanks,
Bipuser -
How to concatenate the values in single row with images or colours
hi all,
i am apex 4.2,
i tried to execute a plsql query for the values concatenate two values into same column
example in my table
i am having teachers list one can teach two or three subjects
in table i am saving like
teacher_id teacher_name salary subjects
1 ram 5000 science,maths
2 gang 4000 maths,science,english
but my report should come like
teacher_id teacher_name salary subjects
1 ram 5000 science maths i have to highlighting these subjects with images or with different colors
2 gang 4000 maths english science
can any one help me please
thanks & regards
pavan
Edited by: Pavan on Apr 9, 2012 4:15 AM
Edited by: Pavan on Apr 9, 2012 4:22 AMFirst of all, i would split the subjects column.
If you for sure only need up to 3 subjects, you could make three columns subject1, subject2, subject3.
If you may have an indefinite number of subjects for each teacher, you might create a detail-table with the subjects for each teacher.
I also would create a list of values for the subjects, either based on static values or based on another table with the subjects allowed.
Now that the subject-names are fixed you could create a subject-image for each subject, named as the subject itself. Then you "construct" the image for each subject as
<img src="#APP_IMAGES##SUBJECT_NAME#.png"/> -
SSRS report with cube – MDX query how to get an extra row with value '0'.
Hello everyone,
I'm unable to write the MDX query to get '0' value as first row in output. Following is my MDX query:
WITH MEMBER [Measures].[Dummy] AS '0'
SELECT NON EMPTY Union( {[Measures].[Amount] },{[Measures].[Dummy]}) ON COLUMNS,
NON EMPTY { ([Customer].[Customer Nbr].[Customer Nbr].ALLMEMBERS * [Fiscal].[Year].[Year].ALLMEMBERS ) }
having [Measures].[Amount] > 5000
ON ROWS FROM [cube]
With above query, the output returns the value '0' as a separate column.
I would like to get it in form of first row for [Measures].[Amount]. Like,
Amount
0
500
200
100
What needs to be changed to achieve the above result? I'm planning to use the above value in line chart to start the line from 0th value as described in following URL. (Note: The below URL is using SQL query and not MDX expressions.)
http://spinerain.blogspot.in/2013/09/ssrs-line-chart-create-stacked-line-and.html
Thanks, Ankit Shah
Inkey Solutions, India.
Microsoft Certified Business Management Solutions Professionals
http://www.inkeysolutions.com/MicrosoftDynamicsCRM.htmlThe round brackets in your expression are forcing an implicit crossjoin between the 3 lines. I would do the following which creates a set of the DummyYear plus the real year members and then crossjoin that with the customer set.
WITH MEMBER [Fiscal].[Year].DummyYear AS '0'
SELECT NON EMPTY {[Measures].[Amount]} ON COLUMNS,
NON EMPTY {[Fiscal].[Year].DummyYear,
[Fiscal].[Year].[Year].MEMBERS} *
[Customer].[Customer Nbr].[Customer Nbr].MEMBERS
having [Measures].[Amount] > 5000
ON ROWS FROM [cube]
http://darren.gosbell.com - please mark correct answers -
How to list selected parent and child rows with values from ADF TreeTable
I created one tree table having three levels using DepartmentsVO, EmployeesVO and
JobHistoryVO where these tables contains parent and child relationship on database.
Then i added one more column to the tree table which displays selectBooleanCheckBox. This
check box is available for parent and child rows in that column.
My first concern is i
want to list out all the parentids and its child ids from three levels where the check
box is selected.
second concern is
if i select the check box for a parent row, then the remaining check boxes for child rows also select automatically which are comes under the parent row.
Thanks in advance.
jkhi Frank,
Thanks for the quick reply...
As I mentioned before I am able to get the children using JUCtrlHierNodeBinding. but wanted to change the value of child row which have specific data.
Is it possible through JUCtrlHierNodeBinding to update data of child and parent?? If so then can you please post the code snippet for the same???
Viral -
How to modify the query to get the output in a single row
Hi All,
Below is the query i have written it works fine
select DISTINCT right(left(CTACCT,13),4) AS LocationNum,
tODS_GLBalance.FiscalYearId AS FiscalYearId,
tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
--tods_GLMetadata.Metric,
Case when
tods_GLMetadata.Metric = 'Gross Margin'
Then SUM(Balance)
Else 0
END AS GrossMargin,
Case when
tods_GLMetadata.Metric = 'Occupancy'
Then SUM(Balance)
Else 0
END AS Occupancy,
Case when
tods_GLMetadata.Metric = 'Payroll Dollars'
Then SUM(Balance)
Else 0
END AS Payroll,
Case when
tods_GLMetadata.Metric = 'CF Sales'
Then SUM(Balance)
Else 0
END AS OperatingSales,
Case when
tods_GLMetadata.Metric = 'Operations'
Then SUM(Balance)
Else 0
END AS OperatingExpenses
-- 0 as payroll
from ods.[JJill].[tODS_GLBalance]
inner join ods.Staging.tODS_INF_GLPCT ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
inner join ods.JJill.tods_GLMetadata ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
where
(tODS_GLBalance.FiscalYearId = 2012) and
(tODS_GLBalance.FiscalMonthOfYearId = 2) and
(right(left(CTACCT,13),4)= 3020)
group by
right(left(CTACCT,13),4),
tODS_GLBalance.FiscalYearId,
tODS_GLBalance.FiscalMonthOfYearId,
tods_GLMetadata.Metric
This is the sample output,
LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
3020 2012 2 -112477.00 0.00 0.00 0.00 0.00
3020 2012 2 0.00 0.00 0.00 -158288.94 0.00
3020 2012 2 0.00 0.00 0.00 0.00 5625.44
3020 2012 2 0.00 0.00 24185.79 0.00 0.00
3020 2012 2 0.00 31075.53 0.00 0.00 0.00
But, i am expecting the output to be something like this
LocationNum FiscalYearId FiscalMonthOfYearId GrossMargin Occupancy Payroll OperatingSales OperatingExpenses
3020 2012 2 -112477.00 31075.53 24185.79 -158288.94 5625.44
Can someone please help me with changing my query to get the desired output?
Please let me know if you have any questions.
ThanksTry this:
SELECT DISTINCT
RIGHT(LEFT(CTACCT,13),4) AS LocationNum, tODS_GLBalance.FiscalYearId AS FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId AS FiscalMonthOfYearId,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Gross Margin' THEN Balance ELSE 0 END ) AS GrossMargin,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Occupancy' THEN Balance ELSE 0 END ) AS Occupancy,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Payroll Dollars' THEN Balance ELSE 0 END ) AS Payroll,
SUM(CASE WHEN tods_GLMetadata.Metric = 'CF Sales' THEN Balance ELSE 0 END ) AS OperatingSales,
SUM(CASE WHEN tods_GLMetadata.Metric = 'Operations' THEN Balance ELSE 0 END ) AS OperatingExpenses
FROM ods.[JJill].[tODS_GLBalance]
INNER JOIN ods.Staging.tODS_INF_GLPCT
ON tODS_GLBalance.PageNum = tODS_INF_GLPCT.CTPAGE
INNER JOIN ods.JJill.tods_GLMetadata
ON tods_GLMetadata.AcctDescription = tODS_INF_GLPCT.CTDESC
WHERE tODS_GLBalance.FiscalYearId = 2012
AND tODS_GLBalance.FiscalMonthOfYearId = 2
AND RIGHT(LEFT(CTACCT,13),4) = 3020
GROUP BY right(left(CTACCT,13),4), tODS_GLBalance.FiscalYearId, tODS_GLBalance.FiscalMonthOfYearId, tods_GLMetadata.Metric -
Mearge Multiple rows of same record in single row with /
Dear Friends
Here I am giving a example, In this example i want to mearge the records containing waybillno 24292 to single record but here i am having seperate tallerno which i want to combine in 1 record with '/'
Please give the solution urgently
WAYBILLNO WAYBILLDT TALLERNO TALLERDAT INVOICEVALUE
24942 31-MAR-11 873000
24942 31-MAR-11 3142 07-MAR-11
24942 31-MAR-11 3145 18-MAR-11
sandy
Edited by: Sandy on 17 May, 2011 4:57 AM/* Formatted on 5/18/2011 10:10:36 AM (QP5 v5.149.1003.31008) */
WITH t AS (SELECT 24942 WAYBILLNO,
'31-MAR-11' WAYBILLDT,
873000 TALLERNO,
NULL TALLERDAT
FROM DUAL
UNION
SELECT 24942,
'31-MAR-11',
3142,
'07-MAR-11'
FROM DUAL
UNION
SELECT 24942,
' 31-MAR-11',
3145,
'18-MAR-11'
FROM DUAL
UNION
SELECT 24943,
'28-MAR-11',
3150,
'08-MAR-11'
FROM DUAL
UNION
SELECT 24943,
' 20-MAR-11',
3155,
'12-MAR-11'
FROM DUAL)
SELECT WAYBILLNO,
MAX (SUBSTR (SYS_CONNECT_BY_PATH (WAYBILLDT, ','), 2)) WAYBILLDTS,
MAX (SUBSTR (SYS_CONNECT_BY_PATH (TALLERNO, ','), 2)) TALLERNOS,
MAX (SUBSTR (SYS_CONNECT_BY_PATH (TALLERDAT, ','), 2)) TALLERDATS
FROM (SELECT WAYBILLNO,
WAYBILLDT,
TALLERNO,
TALLERDAT,
ROW_NUMBER ()
OVER (PARTITION BY WAYBILLNO
ORDER BY WAYBILLDT, TALLERNO, TALLERDAT)
rn
FROM t)
-- WHERE CONNECT_BY_ISLEAF = 1 don't think connect by isleaf is available in 9i
-- so you will need to pick the max and group by waybillno
START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1 AND PRIOR WAYBILLNO = WAYBILLNO
GROUP BY WAYBILLNO
ORDER BY WAYBILLNO
WAYBILLNO WAYBILLDTS TALLERNOS TALLERDATS
24942 31-MAR-11,31-MAR-11,31-MAR-11 3145,3142,873000 18-MAR-11,07-MAR-11,
24943 20-MAR-11,28-MAR-11 3155,3150 12-MAR-11,08-MAR-11 -
How to combine rows with small numbers into single "other" row?
How can I combine rows with value 6(for example) or lower to single row representing the SUM of all this values and label OTHER, so the pie chart will have a chance to display all small values combined?
I'm using Numbers 09HI Peter,
When you write a decimal number, is the decimal separator a period ( . ) or a comma ( , )? If it's a comma, then the syntax error can be corrected by replacing the list separator in the formula, a comma in Jerry's formula, with a semi colon ( ; ):
=SUMIF(B; "<6"; B)
(Added): The two Bs appear in blue 'lozenges' in Jerry's image because that is the way cell (or column) references are displayed in Numbers when a formula has correct syntax.
Regards,
Barry
Message was edited by: Barry
Maybe you are looking for
-
This is a real problem for me, since I listen to a lot of Original Broadway Cast albums, and the songs need to be ordered correctly. What am I doing wrong, and how can I fix it? When I sync to my iPad, the songs all sync in the correct order!
-
Dataloading taking more time from PSA to infocube through DTP
Hi All, when i am loading data to infocube through PSA with DTP, it taking more time. Its taken already 4 days to load. Irrespective of the data the previous loads were completed in 2-3 hrs. This is the first time am facing this issue. Note: There is
-
ANSI escape sequence for "Command" key?
I know there are escape sequences for ctrl (^), alt (~), shift ($), etc that can be used from the command-line, but I'm wondering if there's an equivalent way to invoke the command key (or the apple key or whatever you wish to call it) from a termina
-
I need to visit the HSBC Careers Site website, to perform some sort of assessment for a job I'm applying for; the site asks me to use mozilla firefox 1.5 or 2.0 I, I may of course, be just stupid, but I don't see how I might achieve this trick? Any s
-
TS1424 How do I remove 'stuck' music purchases in my download list ?
I have 2 music purchases in my download list that i can't remove. how do i remove them ?