Displaying single value (Record) into multiple columns
Hi All,
I want to display the single record into multiple columns. Please let me know How to achieve this..
Record:
Lvl Activity Acre
6 Week 4 (Same value to be displayed into 3 columns.)
REquired output:
lvl Activity PH1 PH2 PH3
6 Week 4 4 4
Thanks
Kavi
user533671 wrote:
Hi,
Thanks for immediate reply.
PH1, PH2, PH3, ... will go more columns based on parameter , what we are passing.An single SQL statement cannot have a dynamic number of columns based on the data itself. The projection (columns returned) have to be known before any data is fetched... and that includes some 'parameter' value.
{thread:id=2309172}
You can build a query dynamically, based on a parameter or even on the data, but 99 times out 100 people use dynamic queries where they are not needed.
Perhaps explain to us what you are really trying to achieve and why, and we could suggest some better way.
Similar Messages
-
How to fetch single row data into multiple columns
Hi Have a cursor
which will have SELECT Sun_hrs,Mon_hrs,Tue_hrs,Wed_hrs,Thu_hrs,Fri_hrs,Sat_hrs from OTMaster;
now my cursor has one row of the above columns with this row data I want to insert into other tale as column wise
ex:
my row is like this: Sun_hrs,Mon_hrs,Tue_hrs,Wed_hrs,Thu_hrs,Fri_hrs,Sat_hrs
01:00 01:00 01:00 01:00 01:00 01:00 01:00
now I want to insert the above data into table with loop along with weekday
weekday, OTHrs
1 01:00
2 01:00
3 01:00
4 01:00
5 01:00
6 01:00
7 01:00
which type of variable I need to fetch the records, rowtype or tabletype,
plz help methank you for information, and now I am using UNPIVOT below is my query
SELECT * FROM OTCEILINGMASTER
UNPIVOT(OTHOURS FOR WEEK_DAY IN (SUN_CEILING_HRS AS '1',MON_CEILING_HRS AS '2',TUE_CEILING_HRS AS '3',
WED_CEILING_HRS AS '4',THU_CEILING_HRS AS '5',FRI_CEILING_HRS AS '6',SAT_CEILING_HRS AS '7'));
when I am selecting all the columns (select * from OTCEILINGMASTER) then only the above query is executing I want only two columns from the table however my table has 10 columns.
please looking into this -
To display comma separted value into multiple column
Hi,
I want to display value into multiple column like below
data is like this
col1
res_menaHome:MenaHome
res_menaHomeEmp:MenaHome Employee
res_MDSpecialSer:MD Special Services
res_Smart:Smart
now i want to display like
col1 col2
res_menaHome MenaHome
res_menaHomeEmp MenaHome Employee
res_MDSpecialSer MD Special Services
res_Smart Smart
Thanks in advance.You mean like this?
with q as (select 'res_menaHome:MenaHome' myString from dual)
select substr(myString, 1, instr(myString, ':') - 1) col1,
substr(myString, instr(myString, ':') + 1) col2
from q
COL1,COL2
res_menaHome,MenaHome -
Split one column value and insert into multiple columns
hi
am new to plsql .
i want to split a characters from one column and insert into multiple columns
i tried used substr function the symbol ',' vary his place dynamically ,so i can't apply substr function.
for eg: before split
col1 :
col2 :
col3 :
col4 :
colu5: adsdf,fgrty,erfth,oiunth,okujt
after split
col1 :adsd
col2 :fgrty
col3 :erfth
col4 :oiunth
col5 : adsdf,fgrty,erfth,oiunth,okujt
can anyone help me
thanks
Edited by: 800324 on Dec 23, 2010 8:28 AM
Edited by: 800324 on Dec 23, 2010 8:36 AMHow about:
SQL> create table t
2 (col1 varchar2(30)
3 ,col2 varchar2(30)
4 ,col3 varchar2(30)
5 ,col4 varchar2(30)
6 ,col5 varchar2(30)
7 );
Table created.
SQL> insert into t (col5) values ('adsdf,fgrty,erfth,oiunth,okujt');
1 row created.
SQL> insert into t (col5) values ('x,y');
1 row created.
SQL> insert into t (col5) values ('a,b,c,d');
1 row created.
SQL> select * from t;
COL1 COL2 COL3 COL4 COL5
adsdf,fgrty,erfth,oiunth,okujt
x,y
a,b,c,d
3 rows selected.
SQL>
SQL> merge into t a
2 using ( with t1 as ( select col5||',' col5
3 from t
4 )
5 select substr(col5, 1, instr(col5, ',', 1, 1)-1) col1
6 , substr(col5, instr(col5, ',', 1, 1)+1, instr(col5, ',', 1, 2)- instr(col5, ',', 1, 1)-1) col2
7 , substr(col5, instr(col5, ',', 1, 2)+1, instr(col5, ',', 1, 3)- instr(col5, ',', 1, 2)-1) col3
8 , substr(col5, instr(col5, ',', 1, 3)+1, instr(col5, ',', 1, 4)- instr(col5, ',', 1, 3)-1) col4
9 , rtrim(col5, ',') col5
10 from t1
11 ) b
12 on ( a.col5 = b.col5 )
13 when matched then update set a.col1 = b.col1
14 , a.col2 = b.col2
15 , a.col3 = b.col3
16 , a.col4 = b.col4
17 when not matched then insert (a.col1) values (null);
3 rows merged.
SQL> select * from t;
COL1 COL2 COL3 COL4 COL5
adsdf fgrty erfth oiunth adsdf,fgrty,erfth,oiunth,okujt
x y x,y
a b c d a,b,c,d
3 rows selected.
SQL> Assuming you're on 9i... -
How can I separate one column into multiple column?
How can I separate one column into multiple column?
This is what I have:
BUYER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE
0001 PHONE_NUMBER 555-555-0001
0001 EMAIL [email protected]
0001 CURRENCY USD
0002 PHONE_NUMBER 555-555-0002
0002 EMAIL [email protected]
0002 CURRENCY USD
0003 PHONE_NUMBER 555-555-0003
0003 EMAIL [email protected]
0003 CURRENCY CAD
This is what I would like to have:
BUYER_ID PHONE_NUMBER EMAIL CURRENCY
0001 555-555-0001 [email protected] USD
0002 555-555-0002 [email protected] USD
0003 555-555-0003 [email protected] CAD
Any help would be greatly appreciated.This is another solution. Suppose your actual table's name is test(which has the redundant data). create a table like this:
CREATE TABLE test2 (BUYER_ID number(10),PHONE_NUMBER varchar2(50),EMAIL varchar2(50),CURRENCY varchar2(50));
then you will type this procedure:
declare
phone_number_v varchar2(50);
EMAIL_v varchar2(50);
CURRENCY_v varchar2(50);
cursor my_test is select * from test;
begin
for my_test_curs in my_test loop
select ATTRIBUTE_VALUE INTO phone_number_v from test
where person_id=my_test_curs.person_id
and attribute_name ='PHONE_NUMBER';
select ATTRIBUTE_VALUE INTO EMAIL_v from test
where person_id=my_test_curs.person_id
and attribute_name ='EMAIL';
select ATTRIBUTE_VALUE INTO CURRENCY_v from test
where person_id=my_test_curs.person_id
and attribute_name ='CURRENCY';
INSERT INTO test2
VALUES (my_test_curs.person_id,phone_number_v,EMAIL_v,CURRENCY_v);
END LOOP;
END;
Then you will create your final table like this:
create table final_table as select * from test2 where 1=2;
After that write this code:
INSERT ALL
into final_table
SELECT DISTINCT(BUYER_ID),PHONE_NUMBER,EMAIL,CURRENCY
FROM TEST2;
If you have a huge amount of data in your original table this solution may take a long time to do what you need. -
Split a record into multiple records
Hi,
I have situation where i need to split a record into multiple records.
InputData :
value|BeginDate |EndDate
15 |2002/10/15|2002/10/16
13 |2002/10/13|2002/10/20
19 |2002/10/19|2002/10/23
10 |2002/10/10|2002/10/12
OutPut :
10 |2002/10/10|2002/10/12
13 |2002/10/13|2002/10/15
15 |2002/10/15|2002/10/16
13 |2002/10/16|2002/10/19
19 |2002/10/19|2002/10/23
ThanksHi ,
As a far I understood from your example ,
I have few questions...
1. You have information about the patient in a 1 source table.
2. how u are identifying for patient X u need 5 rows to be created. R u storing these informations in seprate table or how ...
3. if you have these information in a seperate tables ..... a simple cross join in ODI should get you the expected result.....
Or give some more information with a example ..that would be great ...
Thanks -
How to Split Single Outbound Idoc into Multiples
Hi guys
Hope you all are doing good.
Can you please let me know , How to Split Single Outbound IDOC into multiples.
I am looking for some sought of configuration in IDOC/from SHIPMENT Configuration level. Because this needs to be implemented for Shipment IDOCS. Please let me know if this can be done through configurations apart from implementing User exit or copying the outbound shipment function module.
Awaiting for your valuable replies.
Best Regards
ShivaHello,
1. Routes
2. Packaging used
3. Shipment Type
Regards
Waza -
Inserting records into multiple tables
Just thinking ahead, and trying to get my head around the
next stage of my database project.
At the moment I have the following tables :
Candidates
Candidate_ID (autonumber)
Name (text)
1, Iain
2, Fi
3, Rob
Vacancies
Vacancy_ID (autonumber)
Vacancy (text)
1, Cartographer
2, Gardener
3, Occupational therapist
4, Web designer
5, Recruitment manager
Profiles
Profile_ID (autonumber)
Profile (text)
1, Map making
2, Web design
3, Gardening
4, Hand therapy
5, Recruitment
6, Aviation
7, Sport
8, Travel
VacancyProfiles
Vacancy_ID (number)
Profile_ID (number)
1,1
1,2
4,2
2,3
3,4
5,5
5,6
CandidateProfiles
Candidate_ID (number)
Vacancy_ID (number)
1,1
1,2
1,7
1,8
2,3
2,4
2,8
3,5
3,6
3,7
and from there created two queries
CandidatesQuery
SELECT Candidates.Candidate_ID, Candidates.Name,
Profiles.Profile_ID, Profiles.Profile
FROM Profiles INNER JOIN (Candidates INNER JOIN
CandidateProfiles ON Candidates.Candidate_ID =
CandidateProfiles.Candidate_ID) ON Profiles.Profile_ID =
CandidateProfiles.ProfileID;
1, Iain, 1, Map making
1, Iain, 2, Web design
1, Iain, 7, Sport
1, Iain, 8, Travel
2, Fi, 3, Gardening
2, Fi, 4, Hand therapy
2, Fi, 8, Travel
3, Rob, 5, Recruitment
3, Rob, 6, Aviation
3, Rob, 7, Sport
and
Vacancies_Query
SELECT Vacancies.Vacancy_ID, Vacancies.Vacancy,
Profiles.Profile_ID, Profiles.Profile
FROM Profiles INNER JOIN (Vacancies INNER JOIN
VacancyProfiles ON Vacancies.Vacancy_ID =
VacancyProfiles.VacancyID) ON Profiles.Profile_ID =
VacancyProfiles.ProfileID;
1, Cartographer, 1, Map making
1, Cartographer, Web design
2, Gardener, 3, Gardening
3, Occupational therapist, 4, Hand therapy
4, Web designer, 2, Web design
5, Recruitment manager, 5, Recruitment
5, Recruitment manager, 6, Aviation
So from these, I have a Candidates page that is based on the
Candidates table listing just ID, name and tel in a repeat region,
with a link to a details page based on the CandidatesProfiles query
above, and likewise with the Vacancies.
I'm just wondering how this works with editing and adding
records - as on those pages, I want to be able to add /edit fields
from the Candidates and Vacancies tables, but also add/edit the
profiles for each - do i just need my Add/Edit pages to be based on
the same CandidatesProfiles and VacanciesProfiles query / SQL
above?
I get how the page retrieving the data can display the
existing records, including multiple profiles for each in a repeat
region - but am less sure about adding / editing multiple profiles?
Or would it be a two step process - ie have a page to add a
Candidate, and then have a page that displayed the Candidate's
details with a subform where you could add/attach profiles to each
Candidate?
Hope that makes some sense, and someone can point me in the
right direction.
Cheers,
IainThinking about it, would it be possible to have a list of
checkboxes on the insert/edit page, with each asigned a Profile -
so for example :
if checkbox1 is checked, add Candidate1, Profile1
if checkbox2 is checked, add Candidate2, Profile2
etc?
Iain -
Splitting of a CSV File with Multiple Records into Multiple XML File
Dear All,
<b> I am doing a Scenario of CSV to XML Files. I am using BPM for the same. My incoming CSV File has got multiple records. I want to break this Multiple records into Multiple XML Files having one record each.</b>
Can someone suggest how can I break this rather Split this into Multiple XML Files.
Is Multimapping absoltely necesaary for this. Can't we do this without Multimapping. Can we have some workaround in the FCC parameters that we use in the Integration Directory.
Kindly reply ASAP. Thanks a lot to all in anticipation.
Pls Help.
Best Regards
Chakra and SomnathDear All,
I am trying to do the Multimapping, and have 0....unbounded also. Someways it is not working.
<b>
Smitha please tell me one thing...Assigning the Recordsets per Message to 1, does it mean that it will write multiple XML Files as I want.</b>
Also I am usinf Set to Read only. So once the File is read it becomes RA from A. Then will it write the other Records.
I have to use a BPM because there are certain dependencies that are there for the entire Process Flow. I cannot do without a BPM.
Awaiting a reply. Thanks a lot in anticipation.
Best Regards
Chakra and Somnath -
Split flat file column data into multiple columns using ssis
Hi All, I need one help in SSIS.
I have a source file with column1, I want to split the column1 data into
multiple columns when there is a semicolon(';') and there is no specific
length between each semicolon,let say..
Column1:
John;Sam;Greg;David
And at destination we have 4 columns let say D1,D2,D3,D4
I want to map
John -> D1
Sam->D2
Greg->D3
David->D4
Please I need it ASAP
Thanks in Advance,
RH
sqlImports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.IO
Public Class ScriptMain
Inherits UserComponent
Private textReader As StreamReader
Private exportedAddressFile As String
Public Overrides Sub AcquireConnections(ByVal Transaction As Object)
Dim connMgr As IDTSConnectionManager90 = _
Me.Connections.Connection
exportedAddressFile = _
CType(connMgr.AcquireConnection(Nothing), String)
End Sub
Public Overrides Sub PreExecute()
MyBase.PreExecute()
textReader = New StreamReader(exportedAddressFile)
End Sub
Public Overrides Sub CreateNewOutputRows()
Dim nextLine As String
Dim columns As String()
Dim cols As String()
Dim delimiters As Char()
delimiters = ",".ToCharArray
nextLine = textReader.ReadLine
Do While nextLine IsNot Nothing
columns = nextLine.Split(delimiters)
With Output0Buffer
cols = columns(1).Split(";".ToCharArray)
.AddRow()
.ID = Convert.ToInt32(columns(0))
If cols.GetUpperBound(0) >= 0 Then
.Col1 = cols(0)
End If
If cols.GetUpperBound(0) >= 1 Then
.Col2 = cols(1)
End If
If cols.GetUpperBound(0) >= 2 Then
.Col3 = cols(2)
End If
If cols.GetUpperBound(0) >= 3 Then
.Col4 = cols(3)
End If
End With
nextLine = textReader.ReadLine
Loop
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
textReader.Close()
End Sub
End Class
Put this code in ur script component. Before that add 5 columns to the script component output and name them as ID, col1, co2..,col4. ID is of data type int. Create a flat file destination and name it as connection and point it to the flat file as the source.
Im not sure whats the delimiter in ur flat file between the 2 columns. I have use a comma change it accordingly.
This is the output I get:
ID Col1
Col2 Col3
Col4
1 john
Greg David
Sam
2 tom
tony NULL
NULL
3 harry
NULL NULL
NULL -
Transformation Routine to convert single record into multiple
All,
I need your help with ABAP Syntax. My requirement is to take a single record and convert it to multiple records into a DSO with a condition to not create a record if a KF value is 0.
R/3 Data Record:
Employee | Date | Char1 | KF1 | Char2 | KF2 | Char3 | KF3 | Char4 | KF4
Conversion Result into DSO:
Employee | Date | Char1 | KF1
Employee | Date | Char2 | KF2
Employee | Date | Char3 | KF3
Employee | Date | Char4 | KF4 (This record will not be written if no value is in KF4)
I have read about the result table in update rules, however within BI 7.0 Transformations I am unfamiliar as to where the RESULT_TABLE function applies. Has this been replaced by the Expert Routine?
Could any ABAP expert provide sample code as to how I would perform this conversion in a Transformation Routine?
Thanks,
DavidThanks Alex for your response.
I did find a solution to this as it turns out to be fairly simple, however I executed the routine as an Expert Routine instead of a Start Routine. I was advised to do the transformation here.
The basic concept is defined below:
Loop at source_package assigning -kf2.
Append result_fields to result_package.
Endif.
-- Kf3u2026 and so on
Endloop.
Basically the APPEND statement is used to create the additional records. -
Splitting the single record into multiple records based on validity
Hi Guru's,
basically i am an BI consultant with less knowledge on ABAP, can i request your help on the ABAP task.
I am working on HR module which is integrated with SAP BI, the reports will be executed based on calendar month the requirement is i should split the single record into a multiple records based on validity of the record. basically the HR data would be in data from and date to.
below is the logic
Check whether the start and end date of the record are in the same month and year.
If yes nothing changes
If no create multiple records
1st record original start date of the record u2018till end of that month
Following record 1st of the next month u2018till last day of the month
u2026
Last record 1st of the month u2018till original end date.
All fields will have the same values, only the datefrom and dateto fields change.
Can any one please provide me the same code to proceed on my task.
Thanks and Regards,
VenkatHi,
Using Rule group we can split it.
Using Rule Group in SAP-BI Part - 1
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/business-intelligence/s-u/using%20rule%20group%20in%20sap-bi%20%20part%20-%201.pdf
Thanks
Reddy -
Display rows into multiple columns
I have a table in the following format:
id value
a1 0
a2 0
a3 0
a4 0
b1 0
b2 0
b3 0
b4 0
how do I go about displaying it into four columns in the following format:
id1 value1 id2 value2
a1 0 b1 0
a2 0 b2 0
a3 0 b3 0
a4 0 b4 0Hi,
789063 wrote:
I got that error in toad. So now I am testing from command prompt. When you say "command prompt", do you mean SQL*Plus?
Sorry, I don't know much about Toad. If Toad is returning 0 rows, and the same query is returning 8 rows in SQL*Plus, then I suspect you are not connecting to the same database or the same user. ASre you sure you're running the exact same query in both front ends?
Here is the data set that I am testing for:
<pre>
id1 value
smple_val_1 0
smple_val_2 1
smple_val_3 1
smple_val_4 2
smple_other_1 3
smple_other_2 5
smple_other_3 8
smple_other_4 13
some_other_val1 1
some_other_val2 0
some_other_val3 3
some_other_val4 5
</pre>
I am trying to select only 'smple%' in the query, which should display in four columns like:
<pre>
id1 val1 id2 val2
smple_val_1 1 smple_other_1 3
smple_val_2 0 smple_other_2 5
smple_val_3 0 smple_other_3 8
smple_val_4 2 smple_other_4 13
</pre>Is that really the output you want? Why not
ID1 VAL1 ID2 VAL2
smple_val_1 0 smple_other_1 3
smple_val_2 1 smple_other_2 5
smple_val_3 1 smple_other_3 8
smple_val_4 2 smple_other_4 13with the 0's and 1's in the val1 column reversed?
Here is the ddl I used:
<pre>
CREATE TABLE table_x
( id VARCHAR2 (20) PRIMARY KEY
, value NUMBER
INSERT INTO table_x (id, value) VALUES ('smple_val_1', 0);
INSERT INTO table_x (id, value) VALUES ('smple_val_2', 1);
INSERT INTO table_x (id, value) VALUES ('smple_val_3', 1);
INSERT INTO table_x (id, value) VALUES ('smple_val_4', 2);
INSERT INTO table_x (id, value) VALUES ('smple_other_1', 3);
INSERT INTO table_x (id, value) VALUES ('smple_other_2', 5);
INSERT INTO table_x (id, value) VALUES ('smple_other_3', 8);
INSERT INTO table_x (id, value) VALUES ('smple_other_4', 13);
INSERT INTO table_x (id, value) VALUES ('some_other_val1', 1);
INSERT INTO table_x (id, value) VALUES ('some_other_val2', 0);
INSERT INTO table_x (id, value) VALUES ('some_other_val3', 3);
INSERT INTO table_x (id, value) VALUES ('some_other_val4', 5);
</pre>Thanks, that's good.
Where is the explanation of how you get the results you want from that data? There are a lot of different ways to get the same results from the same data, especially from a small set of sample data. I might provide a query that gets the right results for the wrong reasons, and when you run that query on a different set of data, it won't necessarily work. That's exactly what happened before. I guessed at what you wanted, but I guessed wrong. Guessing is not a very efficient or reliable way to solve problems. Don't make people guess: explain what you want.
In particular, explain how you can tell, buy looking at a row and column in the original table, to which row and which column of the output it corresponds. I'm pretty sure that the id column of the table always corresponds to either the id1 or idl2 column of the output, and that value always corresponds to either val1 or val2. From this latest set of sample data, it looks like all the rows in table_x that start with 'smple_val' will correspond to the id1 and val1 columns, and that all therows that start with 'smple_other_' will correspond to the id2 and val2 columns. It also looks like each row of the output represents a unique value of the last character of table_x.id.
If I guessed right this time, then what you want is:
SELECT MIN (CASE WHEN id LIKE 'smple\_val\_%' ESCAPE '\' THEN id END) AS id1
, MIN (CASE WHEN id LIKE 'smple\_val\_%' ESCAPE '\' THEN value END) AS val1
, MIN (CASE WHEN id LIKE 'smple\_other\_%' ESCAPE '\' THEN id END) AS id2
, MIN (CASE WHEN id LIKE 'smple\_other\_%' ESCAPE '\' THEN value END) AS val2
FROM table_x
GROUP BY SUBSTR (id, -1)
ORDER BY SUBSTR (id, -1)
;But this is only a guess. I can't guarrantee that this will work on your real data any better than my last guess did. You'll get better answers faster if you provide an explanation, so that poeple don't have to guess so much. -
Pivoting multiple coulmn values into multiple columns dynamically
Hi,
i have found some topics related to 'pivot' in this forum. but my situation is a lit bit different.
I have a table like the below
create
table #temp
(id
int, code
varchar(8),
routing varchar(50))
insert
into #temp(id,code
,routing
values(1,
'code1',
'route1')
,(1,'code11','route11')
,(2,
'code22',
'route22')
,(2,
'code222',
'route222')
,(2,
'code2333',
'route2333')
,(2,
'code2',
'route2')
,(3,
'code3',
'route3'),
(4,
'code4',
'route4'),
(4,
'code44',
'route44')
ID
CODE
ROUTE
1
code1
route1
1
code11
route11
2
code22
route22
2
code222
route222
2
code2333
route2333
2
code2
route2
3
code3
route3
4
code4
route4
4
code44
route44
And I need to display the table below format including column names. And code/routing columns can repeat not more than 10 times.
id
code
routing
code
routing
code
routing
code
routing
1
code1
route1
code11
route11
2
code2
route2
code22
route22
code222
route222
code2333
route2333
3
code3
route3
4
code4
route4
code44
route44
I am using sql server 2012.
i have benefited alot from this forum. a big thank you to the forum.
I would appreciate your help.Refer below solution with PIVOT. You can extend by using Dynamic Pivot.
--create table #temp (id int, code varchar(8), routing varchar(50))
--insert into #temp (id,code ,routing ) values(1,'code1','route1')
--,(1,'code11','route11'),(2,'code22','route22'),(2,'code222','route222'),(2,'code2333','route2333')
--,(2,'code2', 'route2'),(3,'code3', 'route3'),(4,'code4','route4'),(4,'code44','route44')
;with cte1 as (
select *,row_number() over (partition by id order by code) rn
from #temp
),cte2 as (
select *, case
when id=id then 'code_' + cast(rn as varchar) end codeCol, case
when id=id then 'routing_' + cast(rn as varchar) end routingCol
from cte1
),cte3 as (
select id,code_1,routing_1,code_2,routing_2,code_3,routing_3, code_4,routing_4 from cte2
pivot(max(code) for codeCol in (code_1,code_2,code_3,code_4)) pvt
pivot(max(routing) for routingCol in (routing_1,routing_2,routing_3,routing_4) ) pvt1
select id,
max(code_1) code_1,max(routing_1) routing_1,
max(code_2) code_2,max(routing_2) routing_2,
max(code_3) code_3,max(routing_3) routing_3,
max(code_4) code_4,max(routing_4) routing_4
from cte3
group by id
For dynamic pivot technique refer below query sample,
DECLARE
@cols nvarchar(max),
@stmt nvarchar(max)
SELECT @cols = isnull(@cols + ', ', '') + '[' + T.[NAME] + ']' FROM (SELECT distinct [NAME] FROM PIVOTTEST) as T
SELECT @stmt = '
SELECT *
FROM PIVOTTEST as T
PIVOT
max(T.VALUE)
for T.[NAME] in (' + @cols + ')
) as P'
exec sp_executesql @stmt = @stmt
select * from PIVOTTEST
Regards, RSingh -
How to insert parameter value into multiple columns and rows
Hi All,
I have one procedure insert_tab and I am passing
100~101~102:103~104~105:106~107~108 as a parameter to that procedure. I wanted to insert each numeric value into one column. The output of the table should contain
Table:
Col1 Col2 Col3
100 101 102
103 104 105
106 107 108
Awaiting for your reply..That's not more clear for me...
Anyway, if you really want a procedure for that, try :
SQL> create table tblstr (col1 number,col2 number,col3 number);
Table created.
SQL>
SQL> create or replace procedure insert_fct (p_string IN varchar2)
2 as
3 v_string varchar2(4000):=p_string||':';
4 v_substring varchar2(4000);
5
6 begin
7 while instr(v_string,':') > 0 loop
8 v_substring := substr(v_string,1,instr(v_string,':')-1)||'~';
9 insert into tblstr(col1,col2,col3)
10 values (substr(v_substring,1,instr(v_substring,'~',1,1)-1),
11 substr(v_substring,instr(v_substring,'~',1,1)+1,instr(v_substring,'~',1,2)-instr(v_substring,'~',1,1)-1),
12 substr(v_substring,instr(v_substring,'~',1,2)+1,instr(v_substring,'~',1,3)-instr(v_substring,'~',1,2)-1));
13 v_string:=substr(v_string,instr(v_string,':')+1);
14 end loop;
15 end;
16 /
Procedure created.
SQL>
SQL> show err
No errors.
SQL>
SQL> select * from tblstr;
no rows selected
SQL> exec insert_fct('100~101~102:103~104~105:106~107~108')
PL/SQL procedure successfully completed.
SQL> select * from tblstr;
COL1 COL2 COL3
100 101 102
103 104 105
106 107 108
SQL> exec insert_fct('109~~')
PL/SQL procedure successfully completed.
SQL> exec insert_fct('~110~')
PL/SQL procedure successfully completed.
SQL> exec insert_fct('~~111')
PL/SQL procedure successfully completed.
SQL> select * from tblstr;
COL1 COL2 COL3
100 101 102
103 104 105
106 107 108
109
110
111
6 rows selected.
SQL> Nicolas.
Maybe you are looking for
-
I have an xy graph with three plots. I need a property node or something (I couldn't find what I need) that I can give a value for X and it will return a value for Y. I don't know the value of Y before hand. Basically, I need the value of Y for any g
-
Wireless Mighty Mouse/Bluetooth problems
Good day to you all, ladies and gents! Right, well I have attempted some research on this and it seems that there's quite a few other people that have issues with the Wireless (not so) Mighty Mouse. Mine keeps cutting out. Basically just clicking and
-
Hi Guru's, I want to transfer data from the S039 table into the BW system but I can't create a lis datasource. Nothing found on OSS nor SDN. Could anybody help? Thanks!
-
Unable to install/update programs
Some time in the last couple of weeks I noticed that I am unable to install or update programs. Each time this is attempted I get an error message indicating that I do not have sufficient permissions. My user account is an admin account and appears t
-
Sequence dependency between two different operations
Hi we start setup sequence dependency.when in from and to operations we have same operations with different Item class setuo time is showing in ASCP .but when we have different operations in ascp setuo time is not collected.please help us regards