Reg : Concatenation of a column value with multiple rows... URGENT
Hello,
Could any of u help me in concatenating a column value with
multiple rows ???
For ex : I've the following data from emp table :
DEPTNO ENAME
10 KING'S
30 BLAKE
10 CLARK
10 TOM JONES
30 ALLEN
30 JAMES
20 SMITH
20 SCOTT
20 MILLER
10 MILLER
20 rajeev
I want the following output :
deptno Concat_value
10 KING'S,CLARK,TOM JONES,MILLER
20 Rajeev,MILLER,SMITH,SCOTT
30 BLAKE,ALLEN,JAMES
Thanks in Advance,
Srini
Hello Naveen,
Thanks for ur answer. But I need a single SQL query for getting
what I want. I know the solution in PL/SQL.
Please try it in a single SQL....
Thanks again,
Srini
Similar Messages
-
How To Concatenate Column Values from Multiple Rows into a Single Column?
How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David JohnsonStarting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST FIRST CODES
Lesand Danny 1,2,3
Benedi Eric 7,14Regards
Dmytro -
Concatenate a column value across multiple rows - PDW
We are using PDW based on SQL2014. We require an efficient logic on how to concatenate a column value across multiple rows. We have the following table
T1
(CompanyID, StateCD)
Having following rows:
1 NY
1 NJ
1 CT
2 MA
2 NJ
2 VA
3 FL
3 CA
We need a code snippet which will return following result set:
1
CT,NJ,NY
2
MA,NJ,VA
3
CA,FL
We have tried built-in function STUFF with FOR XML PATH clause and it is not supported in PDW. So, we need a fast alternative.Hi Try this:
SELECT * INTO #ABC
FROM
SELECT 1 AS ID,'NY' AS NAME
UNION
SELECT 1 AS ID,'NJ' AS NAME
UNION
SELECT 1 AS ID,'CT' AS NAME
UNION
SELECT 2 AS ID,'MA' AS NAME
UNION
SELECT 2 AS ID,'NJ' AS NAME
UNION
SELECT 2 AS ID,'VA' AS NAME
UNION
SELECT 3 AS ID,'FL' AS NAME
UNION
SELECT 3 AS ID,'CA' AS NAME
)A
CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800))
DECLARE @TMP VARCHAR(MAX),
@V_MIN INT,
@V_MAX INT,
@V_COUNT INT
SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC
SET @V_COUNT=@V_MIN
WHILE @V_COUNT<=@V_MAX
BEGIN
SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC
WHERE ID=@V_COUNT
INSERT INTO ##CDB (ID, NAME) SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME
SET @V_COUNT=@V_COUNT+1
END
SELECT * FROM ##CDB
OR
SELECT * INTO #ABC
FROM
SELECT 1 AS ID,'NY' AS NAME
UNION
SELECT 1 AS ID,'NJ' AS NAME
UNION
SELECT 1 AS ID,'CT' AS NAME
UNION
SELECT 2 AS ID,'MA' AS NAME
UNION
SELECT 2 AS ID,'NJ' AS NAME
UNION
SELECT 2 AS ID,'VA' AS NAME
UNION
SELECT 3 AS ID,'FL' AS NAME
UNION
SELECT 3 AS ID,'CA' AS NAME
UNION
SELECT 5 AS ID,'LG' AS NAME
UNION
SELECT 5 AS ID,'AP' AS NAME
)A
CREATE TABLE ##CDB (ID INT, NAME NVARCHAR(800))
DECLARE @TMP VARCHAR(MAX),
@V_MIN INT,
@V_MAX INT,
@V_COUNT INT
SELECT @V_MIN=MIN(ID),@V_MAX=MAX(ID) FROM #ABC
SET @V_COUNT=@V_MIN
WHILE @V_COUNT<=@V_MAX
BEGIN
SET @TMP = '' SELECT @TMP = @TMP + CONVERT(VARCHAR,NAME) + ', ' FROM #ABC
WHERE ID=@V_COUNT
SELECT @V_COUNT AS ID ,CAST(SUBSTRING(@TMP, 0, LEN(@TMP)) AS VARCHAR(8000)) AS NAME INTO #TEMP
INSERT INTO ##CDB (ID, NAME) SELECT ID, NAME FROM #TEMP WHERE NAME<>''
DROP TABLE #TEMP
SET @V_COUNT=@V_COUNT+1
END
SELECT * FROM ##CDB
Thanks Shiven:) If Answer is Helpful, Please Vote -
Comparing two column values with multiple Parameter in VC (Indicator)
Hello VC experts,
GM
I would like to know about how to indicate multiple parameter with different colour in same column and also comparing value with adjucent column.
Eg.
Parameters ,, Column1 ,, Column 2 ,, Indicator (Image)
Parameter 1 ,, a1 ,, b1 ,, RED
Parameter 2 ,, a2 ,, b2 ,, GREEN
Parameter 3 ,, a3 ,, b3 ,,
Parameter 4 ,, a4 ,, b4 ,,
In case I : Parameter -1 Column 1 ( value) = more is better compared to Column 2
In case II : Parameter -2 Column 1 ( value) = Less is better compared to Column 2
How to acheive this INDICATOR based value comparison.
Edited by: Sunil B. Mundhe on Mar 7, 2009 6:30 AM
Edited by: Sunil B. Mundhe on Mar 7, 2009 6:38 AMHi
This is possible in VC. You have to insert 'Image' UI in the required table. Add images of alert through 'Image manager' (Tools tab). Select relevant images of alert in 'Image' UI. In display there is option for 'visibility condition' there you enter condition (like if greater than ,true,false).
Like wise you can add multiple 'Image' UIs in that table & based on visibility conditions you will get these alert images in table.
Regards
Sandeep -
I want to display one column values with multiple symbols
i am created one report.
my column name is offshore & on shore i want display 3 values with % symbol, then i want show 4 th value as $ 2000,
but it was allowing only one format $ or % but i need to display symbols with my values.Try the following :
give a name to the following formula like @getvalue
Numbervar x;
if
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("ANI"), CurrentSummaryIndex) = 0 and
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Offshore Other"), CurrentSummaryIndex) = 0 and
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Syntel"), CurrentSummaryIndex)= 0 and
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Employee"), CurrentSummaryIndex) = 0 and
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Contractor"), CurrentSummaryIndex) = 0 and
//(GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Mgt consult"), CurrentSummaryIndex) = 0 and
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Clerical"), CurrentSummaryIndex) = 0 and
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Other"), CurrentSummaryIndex) = 0
then
x:=0
else
x:=(GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("ANI"), CurrentSummaryIndex) +
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Offshore Other"), CurrentSummaryIndex) +
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Syntel"), CurrentSummaryIndex))
(GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("ANI"), CurrentSummaryIndex) +
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Offshore Other"), CurrentSummaryIndex) +
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Syntel"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Employee"), CurrentSummaryIndex) +
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Contractor"), CurrentSummaryIndex) +
//GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Mgt consult"), CurrentSummaryIndex) +
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Clerical"), CurrentSummaryIndex) +
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Other"), CurrentSummaryIndex)
) * 100
Now create a new formula and check the value of the above formula :
if {@getvalue} > 50 Then
"$"&{@getvalue}
else
{@getvalue}&"%"
Hope this will resove the issue.
Thanks,
Sastry -
Display only one row for distinct columns and with multiple rows their valu
Hi,
I have a table having some similar rows for some columns and multiple different rows for some other columns
i.e
o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
9825000111 01-jan-06 'a' 980515464 01-feb-06 c
9825000111 01-jan-06 'a' 991543154 02-feb-06 d
9825000111 01-jan-06 'a' 154845545 10-mar-06 a
What i want is to display only one row for above distinct row along with multiple non distinct colums
ie
o_mobile_no o_doc_date o_status d_mobile_no d_doc_date d_status
9825000111 01-jan-06 'a' 980515464 01-feb-06 c
991543154 02-feb-06 d
154845545 10-mar-06 a
regards,
KumarRe: SQL Help
-
Drill Down between 2 stacked column chart with multiple rows.
Hi,
Can anyone please help me.
1) i have to create stacked column chart with Region and cout of calls for previous 3 quarters.
2) the 2nd stacked column should display the priority with the count of calls for the respective selection of region on the 1st chart..
to achieve this,
i'm using 2 stacked column charts and 1 lebel baseb menu.
from this i can able to get the drill down from label based menu to 2nd stacked column chart but i couldn't able to done the same from 1st stacked coumn chart.
Becoz my data is multiple row for each quarter.
please suggest me to achieve the drill down between 2 stacked column charts.
assume that my data like below.:
coulmns for 1st stacked column chart : Region, Q2,Q3 &Q4
Region Q2 Q3 Q4
Other 3658 3497 497
NA - North
America 3 3 1101
APJK 1 4 597
UK 324
EMEA North 1 1 288
CORPORATE 1 5 215
LA -
Latin America1 2 208
EMEA 1 199
EMEA South 1 1 169
Coulmns for 2nd coumn chart: Region, Priority, Q2,Q3,Q4 ()which is derived from 1st table.
Region Priority Q2 Q3 Q4
Other D: End of Next Day 1568 1613 239
Other C: End of Day 983 893 119
Other A: 2 Hour 631 610 70
Other B: 4 Hour 396 318 56
NA -
North AmericaD: End of Next Day 2 2 514
APJK D: End of Next Day 3 297
NA -
North AmericaC: End of Day 284
NA -
North AmericaA: 2 Hour 1 170
UK D: End of Next Day 157
APJK C: End of Day 1 1 152
Other E: 3 - 5 Business Days 68 58 13
EMEA North D: End of Next Day 1 136
CORPORATE D: End of Next Day 4 107
NA - North America B: 4 Hour 1 104
LA - Latin America D: End of Next Day 1 1 86
EMEA D: End of Next Day 86
UK C: End of Day 85
APJK A: 2 Hour 79
EMEA South D: End of Next Day 72
EMEA North A: 2 Hour 69
EMEA North C: End of Day 56
APJK B: 4 Hour 55
EMEA C: End of Day 1 53
LA - Latin America C: End of Day 54
UK A: 2 Hour 49
EMEA South C: End of Day 1 44
CORPORATE A: 2 Hour 1 43
CORPORATE C: End of Day 44
LA - Latin America A: 2 Hour 1 42
EMEA South A: 2 Hour 1 32
EMEA B: 4 Hour 30
UK B: 4 Hour 30
EMEA A: 2 Hour 27
EMEA North B: 4 Hour 1 26
NA -
North AmericaE: 3 - 5 Business Days 25
LA - Latin America B: 4 Hour 23
EMEA South B: 4 Hour 20
CORPORATE B: 4 Hour 17
APJK E: 3 - 5 Business Days 13
Other F: 6 - 10 Business Days 6 4
Other G: 11 - 20 Business Days 6 1Hi Srinivas,
I'm using label based menu "filterd rows" only but i couldn't bind the drill down with the 1st stacked column chart.
for mor details:
1) i'm having 2 stacked coumn charts & 1 lebel based menu but eventhough i couldn't able to achieve.
if i select the lebel based values then the 2nd stacked column charts is giving detailed valus but if i keep my mouse on the 1st stacked column chart the there is no changes on the 2nd chart..
somewhere i'm mising the binding data between 1st stacked coumn chart & lebel based menu on drill down part.
Becoz i'm having multiple rows. so can you please try your and send me the xlf file using your concept. -
ALV column header with multiple rows and ALV column header span
How could I have in an ALV a column header on several lines and/or a column header that spans on multiple columns?
i.e. I would like to have in an ALV two columns, each with it's own distinct header and additionally another column header for both of the columns, that spans across both columns. How could I program this?Hi,
follow below mentioned code
SET THE LABEL OF THE COLUMN
DATA: hr_weeknum TYPE REF TO cl_salv_wd_column_header.
CALL METHOD lr_weeknum->get_header
RECEIVING
value = hr_weeknum.
CALL METHOD lr_weeknum->set_resizable
EXPORTING
value = abap_false.
hr_weeknum->set_prop_ddic_binding_field(
property = if_salv_wd_c_ddic_binding=>bind_prop_text
value = if_salv_wd_c_ddic_binding=>ddic_bind_none ).
set the text of the column
CALL METHOD hr_weeknum->set_text
EXPORTING
value = 'C Form'.
Regards,
Srini. -
How to convert colon separated column values in multiple rows in report
Hi All,
I want to display colon separated values from a column, in a multi row in report.
For example i have a column1 in a table with value 'A:B:C' , column2 has value '1'.
i want to show in a report three rows using these two columns like
column1 column2
A 1
B 1
C 1Here's one way:
SQL> create table test (col1 varchar2(20), col2 number);
Table created.
SQL> insert all
2 into test values ('A:B:C', 1)
3 into test values ('Dg:Ezs', 2)
4 select * from dual;
2 rows created.
SQL> select
2 t.col2,
3 regexp_substr(t.col1, '\w+', 1, t2.column_value) c1
4 from test t,
5 table(cast(multiset(select level
6 from dual
7 connect by level <= length(t.col1) - length(replace(t.col1, ':', '')) + 1
8 ) as sys.odcinumberlist )) t2
9 order by 2, 1;
COL2 C1
1 A
1 B
1 C
2 Dg
2 Ezs
SQL>Edited by: Littlefoot on Jan 31, 2012 10:13 AM -
Parsing csv values into multiple rows ( URGENT )
Hi All,
I am having source table with below listed data set.
EMPID ADD
101 Chennai,Tamilnadu,India
102 Delhi,India
103 6th Street,Downst,CY,USA
I need to create a View with below data format
EMPID ADD
101 Chennai
101 Tamilnadu
101 India
102 Delhi
102 India
103 6th Street
103 Downst
103 CY
103 USA
I need SQL query ....as I dont have previllages to create PL/SQL :-(
Please help me in this reagrd..
Thanks in advance...
Regards,
Shivauser11938787 wrote:
Hi...
above links deals with how to handle csv files using SQL SERVER...
I need to know about Oracle only...
I knew that the link is for SQL Server but i think you don't need to know about Oracle only, you need to know about how to do it only, I mean the logic.
Once you get the logic, it's quite simple to adapt it to Oracle.
WITH tally AS ( SELECT LEVEL AS ID
FROM dual
CONNECT BY LEVEL <= 4000
emp AS (
SELECT 101 AS EMPID, 'Chennai,Tamilnadu,India' AS AD FROM dual
UNION ALL
SELECT 102 AS EMPID, 'Delhi,India' AS AD FROM dual
UNION ALL
SELECT 103 AS EMPID, '6th Street,Downst,CY,USA' AS AD FROM dual
SELECT EMPID, AD
FROM (
SELECT EMPID
,NULLIF(substr(',' || AD || ',' , ID , instr(',' || AD || ',' , ',' , ID) - ID) , '') AS AD
,ID
FROM Tally
,emp
WHERE ID <= length(',' || AD || ',') AND substr(',' || AD || ',' , ID - 1, 1) = ','
AND instr(',' || AD || ',', ',' , ID) - ID > 0
ORDER BY EMPID, ID
)Regards... -
How to compare single value with multiple values
In my query I have something like this:
A.SOR_CD=B.SOR_CODE where A and B are 2 different tables. This condition is in the where clause. The column in table A has single values but some values in table B have multiple comma separated values (822, 869, 811, ..). I want to match this single
value on the left side with each of the comma separated values. Please let me know how will I be able to do it. The number of comma separated values on the right side may vary.Hi MadRad123,
According to your description, you want to compare single value with multiple values in your query. Right?
In this scenario, the table B has comma separated values, however those comma separated values are concatenated into a string. So we can use charindex() function to return the index of the table A value. And use this index as condition in
your where clause. See the sample below:
CREATE TABLE #temp1(
ID nvarchar(50),
Name nvarchar(50))
INSERT INTO #temp1 VALUES
('1','A'),
('2','A'),
('3','A'),
('4','A'),
('5','A')
CREATE TABLE #temp2(
ID nvarchar(50),
Name nvarchar(50))
INSERT INTO #temp2 VALUES
('1','a,A'),
('2','A,B'),
('3','c'),
('4','A,C'),
('5','d')
select * from #temp1 a inner join #temp2 b on a.ID=b.ID
where CHARINDEX(a.Name,b.Name)>0
The result looks like below:
Reference:
CHARINDEX (Transact-SQL)
If you have any question, please feel free to ask.
Best Regards,
Simon Hou -
Web dynpro screen with multiple rows with columns that can be edited
Web dynpro screen with multiple rows with columns that can be edited individually:
Hi
I am busy creating a screen in web dynpro for ABAP which we would like to make available via Portal ESS (Portal 7).
I need to add 'n type of table (or almost something like Excel) or something in which someone can type a few paycode numbers (there should be lets say 10 blank rows in which info can be typed in and if I click on a button or so, more rows must be added if necessary. Then in the other colums stuff like amounts must be entered which one should also be able to edit then and there.
Can anyone assist in what I can use for this? There does not seem to be some existing element that I can use.
Help will be appreciated.
Regards
DebbieHi Debbie,
Whiel Creating table you need to be care full that use chose INPUT FIELD as the CELL EDITOR. Just guessing that if ur table is not editable u might have choosen TextView as default cell editor type.
check link for details on TABLE UI
[http://help.sap.com/saphelp_erp2005/helpdata/EN/b5/ac884118aa1709e10000000a155106/frameset.htm]
easy way is to first add UI ELEMENT TABLE to your VIEW, then right click over it & select create binding from context. After you have a pop up where you can select what columns you want what should be its cell editor etc.
Greetings
Prashant -
How can I replace column value with a particular value in SQL
Hi All,
Can anyone please tell me how can I format my output with replacing a column value with a specific value which actually depends on the present value of the column
I am executing the following SQL statement
select state,count(id) from <table_name> where composite_dn= <composite_dn_name> group by state;
My Present output is:
State No.Of Instance
1 3
3 28
I want to replace the value in the column state as follows
State No.OfInstances
Completed 3
Faulted 28
I want "1" to be reppaced by "Completed" and "3" to be replaced by "Faulted"
Is is possible with SQL or PL/SQL , if it is then how can I achieve this required result. Please help!!
Thanks in Advance!!
Edited by: Roshni Shankar on Oct 27, 2012 12:38 AMHi Roshni,
I guess this CASE clause can be simulated by a DECODE and also it is very easy to use.
Refer -- http://www.techonthenet.com/oracle/functions/decode.php
select decode(t1.state,t2.state_id,t2.state_name), t1.count_id
from <table_2> t2, (select state,count(id) count_id
from <table_name>
where composite_dn= <composite_dn_name>
group by state) t1
where t1.state = t2.state_id;HTH
Ranit B.
Edited by: ranit B on Oct 27, 2012 2:02 PM
-- link added
Edited by: ranit B on Oct 27, 2012 2:19 PM
-- sample code added -
How can I compare single value with multiple value...
Hello,
I want to compare one value with multiple values, how can it possible ?
Here in attachment I tried to design same logic but I got problem that when I entered value in y that is compared with only minimum value of x, I don't want that I want to compare y value with all the x value and then if y is less then x while loop should be stop.
I want to do so because in my program some time I didn't get result what I want, for example x values is 4,5,6,7,8 and y value is suppose 6 then while loop should be stop but here it consider only minimum number and its 4 here so while loop is not stop even y is less then 7 and 8. So I want to compare y value with all the entered values of x and if y is less then any of x values then while loop should be stop and led should be ON.
Please guide me how can I do so.....
Solved!
Go to Solution.
Attachments:
COMPARISON.vi 8 KBAnkitRamani wrote:
Thank you very mach for your help..
may be i have solved this ....i have made one change in my vi that instead of min. i select max and max. value is compare with the value of y and then if y is less then the max. while loop will be stop other wise its run continuously.
this is working fine...
any ways thanks again for your help and time...
I have to agree with Lewis - his way is more efficient.
Bill
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all. -
Column values with invalid characters
How to find the column values with invalid chararcters
meaning value upper(col) not in ('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
For ex.
1. CDAssyKit,DragonNaturallySpeaking�Preferred7.0,USEnglish
2. CDAssyKit,DragonNaturallySpeaking Preferred7.0,USEnglish
Query should retrieve only the first row, since it has extra � character in the column value.
Thanks for your help.Convert all letters and numbers to an arbitrary letter and then remove that letter. If there are any characters left, they are invalid according to your rules.
select *
from t
where replace(translate(lower(column_name), 'abcdefghijklmnopqrstuvwxyz0123456789', 'a'), 'a') is not null;
Maybe you are looking for
-
Error message while closing mobile sales on a vpn-connected notebook
Hi! We're working with Mobile Sales 4.0 on laptops with WinXP ... When our field service stay connect via vpn with the central server sometimes it happens that an error-message pop up if Mobile Sales shall be closed. The text is "this program is used
-
Deploying ear file in Sun app server
[#|2004-10-15T12:46:20.781+0530|WARNING|sun-appserver-pe8.0.0_01|javax.enterprise.system.stream.err|_ThreadID=11;| javax.management.InstanceAlreadyExistsException: com.sun.appserv:j2eeType=ResourceAdapter,name=StartUpConnector.rar,ResourceAdapterModu
-
Hi all, We have problem in infoset query uploading. we have some queries in system 4.6 we need them in ECC6.0. we r using program RSAQR3TR to download and upload the queries (not import and export). I am able to download but while uploading i am ge
-
Hi All, When entering invoices for services (SES) on MIRO, we have the ability to select a layout for Services. This shows a column called Del Note / Sheet No. I have been trying to find a way to get the Del Note / Sheet No populated with the service
-
I just had a new macbook pro and i updated it to OS X Yosemite. Software update keeps asking me to update iTunes 12.0.1 even though i have updated it several times. Please help. Thanks in advance.