Store multiple values in a column instead of creating additional rows
Hi there :)
Can you guys show me a technique to translate the following result set:
Bus_ID Driver_Name State
1 Alan FL
1 Alan FL
1 Dan WA
2 Lukas FL
2 George WA
Into:
Bus_ID Driver_Name State
1 Alan, Dan FL, Wa
2 Lukas, George FL, WA
How can this result be achieved?
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums. The useless text you posted is not a table! There is no key, and you want to destroy First Normal Form (1NF). Please, please, please read just one book on RDBMS so we will not have to read another posting like
this. It is painful to see this.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Similar Messages
-
How do you lookup multiple values in different columns based on variable criteria?
Essentially, I'd like to be able to do a Vlookup but instead of searching for one value only, search for multiple values in separate columns. A smaller version of my current spreadsheet as an example...
Attack Type ->
Fire
Water
Grass
Fire
1/2x
2x
1/2x
Water
1/2x
1/2x
2x
Grass
2x
1/2x
1/2x
Fire/Water
1/4x
1x
1x
Fire/Grass
1x
1x
1/4x
Grass/Water
1x
1/4x
1x
The headers are the attack types and the list of types to the left are the receiving Pokemon. Fire does half damage (1/2x) to fire types, Water does double damage (2x) to fire types, etc. I'd like to be able to search for specific damages for each type. For example, I'd like to find a Typing that recieves half (1/2x) damage from Fire-type attacks but also recieves double (2x) from Grass-type attacks. I do want more than just two search criteria though seeing as the actual table is much, much larger.
I've tried assigning number values to each damage multiplier and then merging all of them together for a specific typing and doing a VLOOKUP based on checkboxes determining what damage multiplier I want in a few specific types, the rest being filled in to the standard of 1x but the result isn't correct most of the time.Hi Mitchell,
VLOOKUP can be set for accept either an 'exact match' or a 'close match'. Your 17 digit 'number' is actually a 17 character text string (Numbers can handle numbers to a precision of only 15 places). Provided all 17 digits are present, sorting should be the same as for numerical values—the leftmost character is the most significant.
As a text string, your 'number' is sorted/evaluated alphabetically. A 'close match' accepts the 'largest value that is less than or equal to the search value'.
If your search term is 000200000 (a 9 character string), several 'wrong' answers will fit the 'close match' criteria, including all of those listed below:
000200000 (the 'correct' match)
0000xxxxx (x may be any of the three acceptable values)
0001xxxxx (x may be any of the three acceptable values)
The main problem here is that digits in a number (or characters in a text string) have decreasing significance related to their distance from the beginning of the string/number. You want a search in which each character has the same significance as each of the others when compared to the search key. To do that, you need to compare each character in the search string with the character in the same position in the similar string for each type of Pokemon, then take a count of the matches or a sum of the differences.
Here's one approach:
Column A contains labels.
Column B, the 17 digit search term, created in whatever manner you wish, and the similar 17 digit string for each of the characters.
Columns C through S contains a formula that detines, using subtraction, the difference between each digit of the search term and the corresponding digit of each character's profile.
Column C uses SUM() to calculate the total of columns C to S for each row.
T1 uses =MIN(T) to calculate "least different" profile.
Column A is a Header column; Row 1 is a Header row.
Formulas:
C2, and filled right to S2, then down to the last row of data:
=ABS(MID($B$1,COLUMN()-2,1)-MID($B2,COLUMN()-2,1))
T1: =MIN(T)
T2, and filled down column T: =SUM(C2:S2)
The conditional formatting rule set for all body cells in column T is shown below the table.
This may be enough to get you started. Formulas can be tweaked to produce results more closely matching what you're looking for, if necessary.
Regards,
Barry -
Store multiple values into a variable
I was wondering if it was possible to store multiple values into one varaible. Something along the lines of...
Oracle: 10g
--Table xSample (this is obviously a dumbed down version of the table for the sake of showing what I want to accomplish
S_ID YEAR
1 2009
2 2009
3 2009
4 2009
--Query
select s_id
into pID
from xSample
where year = 2009;Basically the reason I was trying to figure out how to store multiple values into a variable is b/c I was going to use that variable (pID) as a parameter and have it's values passed dynamically when the proc was called. The values would go into a query that would look something like:
select *
from cust_data
where person_id in (pID)
aka
select *
from cust_data
where person_id in (1,2,3,4)Not sure if this is possible, but if anyone knows of a way I could accomplish this that would be great.
Edited by: user652714 on Dec 23, 2009 9:37 AMHere's a basic idea building a comma seperated list, then consuming it in another query (taking the in list approach from Tom's post, linked earlier).
create table xsample (s_id number not null, year number);
insert into xsample select level, 2009 from dual connect by level <=4;
commit;
declare
--4000 should be lots ... hopefully?
v_parameter_list varchar2(4000);
begin
--create the comma seperated list
select
substr(max(sys_connect_by_path(s_id, ',') ), 2, 4000)
into
v_parameter_list
from
select s_id, row_number() over(order by 1) as rn
from xsample
where year = 2009
start with rn = 1
connect by prior rn = rn - 1;
--consume the comma seperated list
for x in
with data as
select
trim( substr (txt,
instr (txt, ',', 1, level ) + 1,
instr (txt, ',', 1, level+1)
- instr (txt, ',', 1, level) -1 ) ) as token
from
select ','||v_parameter_list||',' txt
from dual
connect by level <= length(v_parameter_list)-length(replace(v_parameter_list,',',''))+1
select *
from xsample
where s_id in (select * from data)
loop
dbms_output.put_line('next item = ' || x.s_id);
end loop;
end;
/ -
How to store multiple values associated to one key
hello all
In my program I need to store "multiple values associated to one key".
for example : key would be ="T"
Values are = 2,4,5,1,2Plz tell me which data structure I can use for this purpose.
I have tried Hashtable for it, unfortunately it does not support duplicate keys in one Hashtable.
Thanx.
RakeshThe easiest thing to do, is store another data structure as your value for a
particular key. So "T" being your your key, you would associate the value
to be an int[] (if you know the number of sub values) or create a new Vector
for each key, then you don't have to worry about the number of values at
compile time. All the while still using the Hashtable for constant time
look up. So like this:
public void storeMultValues(int[] arr)
Vector v = new Vector();
v.add(new Integer(1));
v.add(new Integer(2));
v.add(new Integer(3));
this.hashtable.put("T", v);
}See if you can work with that.
-Cludge -
How to store Multiple values with restriction in Oracle 9i
Hi,
I am using oracle 9i R2 and i would like to know that how can i store multiple values and restrict some of values into oracle table?
ex.
I need to create table or inserting into existing table like below:
ID will be Primary/Unique key and each ID has multiple dept but each ID to have only 1 “X” dept, only 1 “Y” dept and only 1 “Z” dept… but, can have multiple “W” dept
What will be the best option to create/store data like this?
Like Table level Constraint (Unique or Check), Triggers or pl/sql?
ID DEPT
1 X
1 Y
1 Z
1 W
2 X
2 Y
2 Z
2 W
2 W
2 WHi,
Other solution:
Function:
CREATE OR REPLACE FUNCTION my_unique_function(p_dep IN VARCHAR2) RETURN VARCHAR2
DETERMINISTIC AS
BEGIN
IF (p_dep = 'X' OR p_dep = 'Y' OR p_dep = 'Z') THEN
RETURN p_dep;
ELSE
RETURN NULL;
END IF;
END;
/Test:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> create table emp(id number, dept varchar2(30));
Table created
SQL>
Function created
SQL> CREATE unique index ix_emp on emp(my_unique_function(dept));
Index created
SQL> insert into emp(id,dept) values (1, 'X');
1 row inserted
SQL> insert into emp(id,dept) values (2, 'X');
insert into emp(id,dept) values (2, 'X')
ORA-00001: unique constraint (HR.IX_EMP) violated
SQL> insert into emp(id,dept) values (3, 'Y');
1 row inserted
SQL> insert into emp(id,dept) values (4, 'Y');
insert into emp(id,dept) values (4, 'Y')
ORA-00001: unique constraint (HR.IX_EMP) violated
SQL> insert into emp(id,dept) values (5, 'Z');
1 row inserted
SQL> insert into emp(id,dept) values (6, 'Z');
insert into emp(id,dept) values (6, 'Z')
ORA-00001: unique constraint (HR.IX_EMP) violated
SQL> insert into emp(id,dept) values (7, 'W');
1 row inserted
SQL> insert into emp(id,dept) values (8, 'W');
1 row inserted
SQL> Regards, -
Which table stores the value of status column in leave request.
Which table stores the value of status column in leave request.If i give pernr ,absence type and date how would i get the status
Thanks
Bala DuvvuriHi,
PTREQ_ACTOR - Request Participant
PTREQ_ATTABSDATA - Request Data for Attendances/Absences
PTREQ_BATCH - Time Stamp for Run of Background Jobs
PTREQ_CKEY_MAPP - Cache Assignment Table
PTREQ_HEADER - Request Header
PTREQ_ITEM_TYPES - Request Item Types
PTREQ_ITEMS - Request Items
PTREQ_NOTICE - Note for Request
PTREQ_STATUS_CHK - Check Methods for Status Transitions
PTREQ_STATUS_TRA - Status Transfers
PTREQ_TYPE - Request Types
PTREQ_XFEREVENTS - Permitted Status Transitions
PTREQ_XFEREVNT_T - Texts for Status Transitions
Value of staus column you can check it PTREQ_STATUS_CHK -
Hi All:
I am trying to create multiple profiles, using unified profile types, to
store multiple values for same properties. Here my intention of using
'unified profile types' is to create multiple profiles (to store multiple
values for a property). All the properties are stored in the same database
maintained by Personalization server. Also, I am trying to use the same
'USER' ejb as profile class/home/pk/jndi.
The scenerio is,
define unified profile types (Business, Vacation) using Personalization
admin tools, using com.beasys.commerce.axiom.contact.User,
com.beasys.commerce.axiom.contact.UserHome,
com.beasys.commerce.axiom.contact.UserPk,
com.beasys.commerce.axiom.contact.User for Profile Class, Home, Pk class,
JNDI name respectively.
Define Property set 'HotelCommerce' with property
HotelProp as single, restricted, text (valid values Single, Double)
Now you can use the attached jsp files to login as a user and try to set the
property value for HotelProp for each profile. As per my understanding, I
was expecting that I can set different values for the property 'HotelProp'
for each profiles. But unexpectedly, all the profiles get the same value.
Question. is it the correct behavior? if yes, how can I achieve this
functionality?
if not, do you see any problem in my scripts?
your answer asap is appreciated. we need to make decision on using
Personalization server v/s developing our own Personalization server!!!:)
thanks,
-rajesh
PS: I have tried 'Unified Profile Example' type too, but that did not work.
[propsettest.jsp]
[home.jsp]I am trying to create multiple profiles, using unified profile types, to
store multiple values for same properties. Here my intention of using
'unified profile types' is to create multiple profiles (to store multiple
values for a property). All the properties are stored in the same database
maintained by Personalization server. Also, I am trying to use the same
'USER' ejb as profile class/home/pk/jndi.Hello Rajesh,
This is not the purpose of the UUP. The UUP is used to allow existing
database schemas to be aggregated with the existing Weblogic Personalization
Server database schema to provide a single, customized user profile with which
to maintain the user properties (
http://e-docs.bea.com/wlcs/p13n/users.htm#1068901 )
If you want to have properties that change value based on some "profile" or
classification of a user, then you should use classifier rules to change the
user from "OnVacation" to "AtWork" or "AtHome". You can use these classifier
rules to select content for the user or conditionally execute logic (
http://e-docs.bea.com/wlcs/p13n/rules.htm )
Ture Hoefner
BEA Systems, Inc.
1655 Walnut Street; suite 200
Boulder, CO 80302
www.beasys.com -
How to store multiple values in a coloum for a particaular row?
By mistake i posted this in abap general forum but i think this question should belong to Data Dictionary section
I want to design a table where we can store a table where we can save multiple values of column for a particular row. how to achieve this ? thanks in advance.
Example
id name val1 val2
001 abc 1 a
2 b
3 d
4 eyou can use deep structures to achieve this.
or may be a simpilar approach based on the example that you have mentioned will be to create a table with all the primary keys that you want with an additional key field which will behave as a counter. some standard table do you this technique eg: PLMK where zaehl is a counter field which part of the kley fields.
cheers, Prabhakaran -
How to represent multiple values in one column
Hi,
I need some help in designing a schema for this problem.
I have :
- 4 domains
- In each domain there will be many groups
- users belong to multiple groups in multiple domains
Eg.
user1 might be in groups g1, g2 and g3 in domains d1, d2
In a text file I represent it like this:
user1 | d1 | g1,g2,g3
user2 | d2 | g1, g2
etc.,
How do design a schema for this. I don't like the idea of having comma
separated values in columns.
Thanks.Good instincts. You don't want to have comma-separated values in a column, that violates basic normalization rules.
You would probably want something like this
CREATE TABLE usr (
user_pk
user_id
CREATE TABLE grp (
group_pk
group_id
CREATE TABLE domain (
domain_pk,
domain_name
CREATE TABLE domain_group (
domain_pk,
group_pk
CREATE TABLE user_group (
user_pk,
group_pk
)where you create separate tables that map different things to each other. domain_group shows which groups are associated with a particular domain, user_group shows which users are associated with a particular group.
Justin -
Multiple value in one column issue
Dear proffessionals,
i'm trying to put more than one value in one column, so i have next problem:
1. Query select cr_pjid from acc_users where username='ACCBTPS121' give result
CR_PJID
'26','63'2. Query select * from acc_accbtp_nova_view where ed_id=2 and to_char(pj_id) in ('26','63'); return 186 rows.
3. Query: select * from acc_accbtp_nova_view where ed_id=2 and
to_char(pj_id) in (select cr_pjid
from acc_users
where username='ACCBTPS121'); doesn't return any row... :(
Could anyone help me ?
Thx in advance,
AdnanAfter researching, I think that the best idea is to create another table with multiple rows and different values for one column...
[http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425] -
Retrieving multiple values from one column in SELECT statement
Hi,
I have a slight dilemma in that I'm trying to pull down all the values from a column from a select statement that includes some JOINS in it.
If I run the query at the SQL Plus prompt, it pulls back all the values/rows.
When I run the select (and prepared ) statement in my JSP, it only pulls back one of the 4 values I'm trying to retrieve.
e.g.
at the DB level :
SELECT role_name, CC_ID FROM votetbl a
INNER JOIN APPROVERS b ON
a.BUSVP = b.BUSVP AND
a.BRANCH = b.BRANCH
WHERE CC_ID = 1688this will return:
ROLE_NAME CC_ID
ops 1688
ops 1688
comply 1688
legal 1688
comply 1688
When run in my JSP, like so:
String primID3a = request.getParameter("primID");
Statement stmtovoter = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
String prepvotSQL = "SELECT role_name, CC_ID FROM votetbl a INNER JOIN APPROVERS b ON a.BUSVP = b.BUSVP AND " +
"a.BRANCH = b.BRANCH WHERE CC_ID = ?";
PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
prepvotstmt.setString(1, primID3a);
ResultSet rest3 = prepvotstmt.executeQuery();
rest3.next();
String votecat = rest3.getString(1);
out.println("Vote category: "+votecat);I only get ops returned.
Do I need to run an enumerator? Or reqest.getParameterValues or use a while statement around the results set?
Any feedback and direction here is welcomed!
Thanks!Actually, I tried looping and still only get 1, but returned several times.
i.e.
PreparedStatement prepvotstmt = connection.prepareStatement(prepvotSQL);
prepvotstmt.setString(1, primID3a);
ResultSet rest3 = prepvotstmt.executeQuery();
rest3.next();
String votecat = rest3.getString(1);
while (rest3.next()) {
out.print("category roles "+votecat);
}then I get returned the following:
admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admincategory roles admin
like so.
Where as at the DB level I get
ROLE_NAME CC_ID
admin 1688
ops 1688
ops 1688
ops 1688
ops 1688
ops 1688
ops 1688
ops 1688
risk 1688
comply 1688
legal 1688
legal 1688
ops 1688
comply 1688
Maybe the while should go around the getString(1) designation? But I was thinking I'd tried that and gotten invalid cursor error
Something is definitely amiss, between the prepared statement in the servlet and the SELECT statement at the DB level.
I can totally hardcode the statement in the servlet or JSP and it will return one value potentially several times, but only one.
Other times, it will not return a value at all, even though one resides in the db.
Yet go to the DB/SQL Plus prompt and it returns perfectly. I can simply copy and paste the SELECT statement from the out.print line I made and it works like a champ in SQL Plus. Any ideas why the same exact thing cannot return the proper values within the servlet/JSP?
Yeeeeeeesh!!! : (
Message was edited by:
bpropes20 -
Multiple values in report column
Hi there,
I have a problem that i hope you can help me with.
I have a value in a tabel cell like P:E which actually means two values: Post, E-mail.
When I make a report how can i make it so that it shows the values Post, E-mail instead of P:E?
Thank you in advance.Anon.,
You could set something like this as the region report source:
SELECT substr(mycol,1,instr(mycol,':')-1) Post
, substr(mycol,instr(mycol,':')+1) Email
FROM mytableAndy -
Display multiple values in a column in ALV
I need to display plant order number from AFPO and PLAF table in reference to Goods Recepient(WEMPF) field.
now in final internal table I assign AFPO--> Plant number value to PLNUM column of ALV.
how do I add value to same column based on WEMPF common value for both table and append value to PLNUM column below value fetched from AFPO table.
code for getting value from PLAF table.
SELECT WEMPF PLNUM
FROM PLAF
INTO TABLE IST_PLAF
FOR ALL ENTRIES IN IST_AFPO
WHERE PLNNO = IST_AFPO-WEMPF
AND ......
Point is for some WEMPF field entried their will be number of entries in AFPO and PLAF table (in PLNUM column) so how I do displaying entries from both tables in single row??Hi Ankitkumar Dineshkumar Gautam,
SAP would say: "This is a consulting issue". I would say: What's your problem? Look at some samle programs.
Regards,
Clemens -
Store the value in BLOB column data type
Hi All,
I have a file of about 5MB. I want to store this in BLOB column data type of a table.
Can we compress this file to store and when we take uncompress the same...or how do we do it.
and what is the procedure to store this....
pls. help me
Thanks,
NareshHi skud
i juast want to store the agent code to variable.if i did get ur point...
Why don't u just use a simple assign statment for example...
DECLARE
V_VALUE NUMBER;
BEGIN
V_VALUE := LC354 ; -- IF it was a value as LC354 static i mean
-- or u could use any value
V_VALUE := :ur_form_item_name; --- if it was dynamic
END;That's it .
Hope this helps...
Regards,
Ammatu Allah. -
OpenScript script variables - can store multiple values or an array?
Hello,
I'm helping with a proof-of-concept for driving the Primavera P6 web services using OpenScript, and I'm having a bit of trouble using the script variables. One of the web services can return anywhere from 0 to many objects, and I was trying to save those object IDs into a script variable. The built-in "substitute variable" seemed to work great, but the variable only contains the last result, not all of them. Here's the line that's saving the value:
http.solve("objIdsToDelete", "<ObjectId>(.+?)</ObjectId>", "", true, Source.Html, 0, EncodeOptions.None);
Even if there are, for example, 5 <ObjectId> in the response, the variable only has the last result... Any suggestions on how I can tweak this (different regular expression?) to either store an array or a comma-separated list of all the values?
Thanks!
-Troy NewtonHi Troy,
Sorry about my last answer. It wasn't too specific. So if you want to collect the whole array instead of a specific value (referenced by the index) you would change e.g.
http.solve("formsload.loginsubmit_1",
"FORM_SUBMIT_BUTTON':'(.+?)'", "", false, Source.Html,
1, EncodeOptions.None);
which would give you the second value from the array (remember that arrays are indexed from 0) to
http.solve("formsload.loginsubmit_1",
"FORM_SUBMIT_BUTTON':'(.+?)'", "", false, Source.Html,
null, EncodeOptions.None);
Notice the null, this will return an array to the coolection. You can then reference these by:
String myStrings[]=getVariables().getAll("formsload.loginsubmit_1");
info("Number of elements in array is :" + myStrings.length);
for (int i=0;i<myStrings.length;i++)
info("Element Number " + i + ":" + myStrings [ i ] );
This will result in an output like:
0 Passed Comments: Number of elements in array is 2
0 Passed Comments: Element Number 0: Submit Button
0 Passed Comments: Element Number 1: Cancel
I hope this helps.....
Regards
Wayne.
Edited by: byrne_wayne on Nov 26, 2010 1:40 PM
Edited by: byrne_wayne on Nov 26, 2010 4:42 PM
Maybe you are looking for
-
Gif animation is not displayed on the JEditorPane
gif animation file is loaded to this pane, it is played for one time and then changed to "cannot load image" icon. Is it somehow related to the JEditorPane, and if yes, than how???
-
How to use Submit in background when report name is not static
Hi all, I have an FM to which report name is being sent as an input parameter. So based on the report name I need to call that particular report in background and send the output as a HTML format to dealer's MAIL ID which is also sent as an input par
-
Sensing a loss of connection without explicitly sending a message
First I need to know if I am even on the right forum since I don't have a clue whether the Sun Java System Message Queue and the Sun ONE Message Queue, v3.0.1 are the same animal. Since there was no forum for the Sun ONE Message Queue I'm assuming th
-
Hi All, I'm using ECC 6.0 IDES.When I'm trying to post a goods receipt for a PO using Migo,I got a short dump like No RFC destination is defined for SAP Global Trade Services Also there is some info in sourcecode like.... when a goods movement for an
-
Gnome panel 3.2 - I am not able to see clock and date well
Hello all, I am using Gnome in fallback -mode. I upgraded my gnome-panel to version 3.2 and after upgrading I am not able to see date and time information well. This information have shown a dark grey color, which is very difficult to see because bac