Mapping a column with comma seperated values
Hi,
I have two tables
1. Tasks (task_id, task_description)
2. Task_assignment (username, task_assignment_value)
the task_assignment_value has a comma seperated list of task_ids.
What is the best ways to map the tables ?
Thanks in advance.
Moinuddin Mohammed
I have a couple of attributes where I do this. From TopLink's perspective, I just map it as a String. Then, in my accessors for the attribute, I transform the primitive between the String and an Array or however the rest of the app wants to see the attribute.
Here's an example that's actually more complicated than absolutely necessary. The mapped attributed is indicatorValueListString. It is lazily converted to an Array of Enums when it is first accessed. And it is converted back to a String in the preWriteEventCallback that is mapped in the TopLink descriptor.
This implementation attempts to minimize the number of times the String<->Array conversion takes place, but if that's not a concern, it could be made much more simple. Also, at my company we privately manage collections with the Collection classes for dynamic allocation, but publicly exchange Arrays for type-safety. This could also be factored out. ValuedEnumUtils basically manages asking the enum for its delimiter and performing the actual conversion between a String and an Array or back.
private String indicatorValueListString;
private List indicatorValueSelections;
private List indicatorValueSelections() {
if (indicatorValueSelections == null) {
indicatorValueSelections = new ArrayList();
if (indicatorValueListString != null) {
indicatorValueSelections =
java.util.Arrays.asList(ValuedEnumUtils.decodeEnumString(
IndicatorValueEnum.class,indicatorValueListString));
return indicatorValueSelections;
private void indicatorValueSelections(List newIndicatorValueSelections) {
indicatorValueSelections = newIndicatorValueSelections;
public IndicatorValueEnum[] getIndicatorValueSelections() {
return (IndicatorValueEnum[])indicatorValueSelections().toArray(new IndicatorValueEnum[0]);
public void setIndicatorValueSelections(IndicatorValueEnum[] newIvSelections) {
indicatorValueSelections(java.util.Arrays.asList(newIvSelections));
public boolean addIndicatorValueSelection(IndicatorValueEnum anIvEnum) {
return indicatorValueSelections().add(anIvEnum);
public boolean removeIndicatorValueSelection(IndicatorValueEnum anIvEnum) {
return indicatorValueSelections().remove(anIvEnum);
public void preWriteEventCallback(DescriptorEvent aDescriptorEvent) {
// Note: Not using accessor to avoid lazy initialization if no changes
// are necessary.
if (indicatorValueSelections != null) {
indicatorValueListString =
ValuedEnumUtils.encodeEnumString((ValuedEnum[])indicatorValueSelections.toArray());
}
Similar Messages
-
Query on column with comma separated values
I have a proposed table with unnormalized data like the following:
ID COLA COLB REFLIST
21 xxx zzz 24,25,78,412
22 xxx xxx 21
24 yyy xxx 912,22
25 zzz fff 433,555,22
.. ... ... ...There are 200 million rows. There is maximum of about 10 IDs in the REFLIST, though typically two or three. How could I efficiently query this data on the REFLIST column? e.g. something like:
SELECT id FROM mytable WHERE :myval in reflistLogically there is a many to many relationship between rows in this table. The REFLIST column contains pointers to ID values elsewhere in the table. The data could be normalized so that the relationship keys are in a separate table (in fact this is the current solution that we want to change).
ID REF
21 24
21 25
21 78
21 412
22 21
24 912
... ...The comma separated list seems instinctively like a bad idea, however there are various reasons for proposing it. The main reason is because the source for this data has it structured like the REFLIST example. It is an OLTP-like system rather than a data warehouse. The source code (and edit performance) would benefit greatly from not having to maintain the relationship table as the data changes.
Going back to querying the REFLIST column, the problem seems to be building an approriate index for the data. The ideas proposed so far are:
<li>Make a materialized view that presents the relationships as normalized (e.g. as in the example with ID, REF columns above), then index the plain column - the various methods of writing the view SQL have been widely posted.
<li>Use a Oracle Text Index (not something I have ever had call to use before).
Any other ideas? Its Oracle 10.2, though 11g could be possible.
Thanks
JimSomething like this ?
This is test demo on my 11.2.0.1 Windows XP
SQL> create table test (id number,reflist varchar2(30));
Table created.
SQL> insert into test values (21,'24,25,78,412');
1 row created.
SQL> insert into test values (22,'21');
1 row created.
SQL> insert into test values (24,'912,22');
1 row created.
SQL> insert into test values (25,'433,555,22');
1 row created.
SQL> select * from test
2 where
3 ',' || reflist || ',' like '%,22,%';
ID REFLIST
24 912,22
25 433,555,22
SQL>Source:http://stackoverflow.com/questions/7212282/is-it-possible-to-query-a-comma-separated-column-for-a-specific-value
Regards
Girish Sharma
Edited by: Girish Sharma on Jul 12, 2012 2:31 PM -
Rows into single column with comma seperator
Hi Friends,
I have the following Query
select A.tradeid||','||A.TICKER||'|'||A.SUBORDINATION||'|'||A.CUSIP||'|'||A.DOCCLAUSE||'|'||A.CURRENCY from table A
where A.ticker in ('LYME','GAADF') and A.tradeid in('456777')
which is returning
456777,LYME|SENIOR UNSECURED|Z1700990|MM|USD
456777,GAADF|SENIOR UNSECURED|Z1246790|MM|USD
I want the result set as:
456777,LYME|SENIOR UNSECURED|Z1700990|MM|USD,456777,GAADF|SENIOR UNSECURED|Z1246790|MM|USD
Please help me to get the result set
Thanks,
ragu.
Edited by: user533548 on Apr 3, 2009 12:54 AM
Edited by: user533548 on Apr 3, 2009 12:55 AMyou could do
select max (ltrim (sys_connect_by_path (tradeid||'|'||TICKER||'|'||SUBORDINATION||'|'||CUSIP||'|'||DOCCLAUSE||'|'||CURRENCY, ','), ','))
from (
select tradeid
, ticker
, subordination
, cusip
, docclause
, currency
, row_number() over (partition by tradeid
order by null
) rn
from x)
start with rn = 1
connect by rn = prior rn + 1like in
SQL> with x as
2 (
3 select 456777 tradeid ,'LYOE' ticker ,'SENIOR UNSECURED' subordination,'Z1830990' cusip,'MM' docclause,'USD' currency from dual union all
4 select 456777 tradeid ,'GAZDF','SENIOR UNSECURED','Z8446790','MM','USD' from dual
5 )
6 select max (
7 ltrim
8 (sys_connect_by_path (tradeid||'|'||TICKER||'|'||SUBORDINATION||'|'||CUSIP||'|'||DOCCLAUSE||'|'||CURRENCY
9 , ',')
10 , ',')) str
11 from (
12 select tradeid
13 , ticker
14 , subordination
15 , cusip
16 , docclause
17 , currency
18 , row_number() over (partition by tradeid
19 order by null
20 ) rn
21 from x)
22 start with rn = 1
23 connect by rn = prior rn + 1
24
SQL> /
STR
456777|GAZDF|SENIOR UNSECURED|Z8446790|MM|USD,456777|LYOE|SENIOR UNSECURED|Z1830990|MM|USD -
Have a column which is having comma seperated values.. and i am trying to s
Have a column which is having comma seperated values.. and i am trying to seperate it.
I am trying to create a stored procedure ..Version 11g xe. .and apex version 4..
Here is the part of code..I cant make a procedure. .cause my statement consist with clause..
create or replace procedure ins_adv_invoice
(mmagazine_no number,madvtno number,missueno number,msection varchar2,mpagenumber varchar2,msalesman_code varchar2)
is
cursor cx is with testa as
(select pagenumber name from advertiser)
select regexp_substr(pagenumber, '[^,]+', 1, rownum) result
from advertiser
connect by level <= length(regexp_replace(pagenumber, '[^,]+')) + 1
where advt_no = madvtno;
begin
for xxx in cx
loop
insert into adv_invoice (magazine_no,advtno,adissue,section,page_number,salesman_code)
values (mmagazine_no,madvtno,missueno,msection,xxx.result,msalesman_code);
end loop;
end;
But when i run this .. it doesnt create procedure. .I get he following error..
LINE/COL ERROR
5/14 PL/SQL: SQL Statement ignored
9/69 PL/SQL: ORA-00933: SQL command not properly ended
SQL>
Still not able to figure it out..Can any one help..
ThanksChange the query to swap the last two lines:
cursor cx is with testa as
(select pagenumber name from advertiser)
select regexp_substr(pagenumber, '[^,]+', 1, rownum) result
from advertiser
where advt_no = madvtno
connect by level <= length(regexp_replace(pagenumber, '[^,]+')) + 1;
... -
How to store Comma Seperated Value in a File with Jsp
Hai friends,
I need to get all the filed values like Empname,salary ,location..........
and at the end of jsp page i have to put a browse button when i choose a file using theis browse button the total content in the form shoud store in that file as comma seperated values.1. Create JSP
2. When you click the button call the event that saves the data in CSV format
Your question is so broad, I don't have exact answer for you.
What have you done so far?
The man with blues. -
Downloading into a text file with comma seperation
hey experts,
well i want to download various fields of an internal table into a text file.but the hitch is that all the columns should be seperated by a comma.something like csv.
could you please help me with this.?
i have tried using gui download but the seperator field was not working.
thanks in advance...
regards,
sandra.hey sandra,
for comma seperation and downloading ,you can use the following fm.
here the i_field seperator should be given as "," as in ur case.
i_tab3 is the table from which the values are being fetched.
and i_tab2 is the table conatining the comma seperated values.
CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = ','
I_LINE_HEADER =
I_FILENAME =
I_APPL_KEEP = ' '
TABLES
I_TAB_SAP_DATA = I_TAB3
CHANGING
I_TAB_CONVERTED_DATA = I_TAB2
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
after this u can use the gui download fm as required.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = TESTFILNA
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = 'x'
HEADER = '123'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = I_TAB2
FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
hope this helps u.
do reward points if useful.....:-) -
How to query the comma seperated values stored in Database
Hi,
I have a strange scenario, I am storing the specific data as a comma seperated value in the database. I want to query the DB with the comma seperated value as a Bind variable against the comma seperated value stored in DB.
For eg : The data stored in DB has
Row1 - > 1,2,3,4,5,6,7,8
Row2 - > 4,5,6,7,8,9,10
When I pas the Bind variable as '4,8' I should get Row1 and Row2 .
Quick help his highly appreciated.. Thanks in AdvanceOh, and if you actually wanted the data returned rather than just the row primary keys....
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as rw, '1,2,3,4,5,6,7,8' as txt from dual union all
2 select 2, '4,5,6,7,8,9,10' from dual union all
3 select 3, '1,6,7,9' from dual)
4 -- end of test data
5 ,r as (select '4,8' as req from dual)
6 -- end of required data
7 ,split_t as (select rw, regexp_substr(txt, '[^,]+', 1, rn) as val
8 from t, (select rownum rn from dual connect by rownum <= (select max(length(regexp_replace(t.txt, '[^,]'))+1) from t))
9 where regexp_substr(txt, '[^,]+', 1, rn) is not null
10 )
11 ,split_r as (select regexp_substr(req, '[^,]+', 1, rownum) as val
12 from r
13 connect by rownum <= length(regexp_replace(req, '[^,]'))+1
14 )
15 --
16 select distinct t.rw, t.txt
17 from split_t st join split_r sr on (st.val = sr.val)
18 join t on (t.rw = st.rw)
19* order by 1
SQL> /
RW TXT
1 1,2,3,4,5,6,7,8
2 4,5,6,7,8,9,10
SQL> -
Hi All.
I have a control file which i need to add a column with header data value.
example
data file:
123456;201303
santiago;producto1;100
santiago;producto2;200
valparais;producto1;400
valparais;producto3;900
The control file skip the first column and load the three columns on the table, but, now i need to add other column with 201303 value constant of the first record and load it on the table.
Then
select * from table:
santiago producto1 100 201303
santiago producto2 200 201303
valparais producto1 400 201303
valparais producto3 900 201303
How i do this in the control file?
Regards!SCOTT@orcl_11gR2> host type test.dat
123456;201303
santiago;producto1;100
santiago;producto2;200
valparais;producto1;400
valparais;producto3;900
SCOTT@orcl_11gR2> host type test1.ctl
options (load=1)
load data
infile test.dat
replace
into table onecol_onerow
fields terminated by ';'
trailing nullcols
(filler1 filler, newcol)
SCOTT@orcl_11gR2> host type test2.ctl
options (skip=1)
load data
infile test.dat
append
into table test_tab
fields terminated by ';'
trailing nullcols
(col1, col2, col3,
newcol expression "(select newcol from onecol_onerow)")
SCOTT@orcl_11gR2> create table onecol_onerow
2 (newcol number)
3 /
Table created.
SCOTT@orcl_11gR2> create table test_tab
2 (col1 varchar2(15),
3 col2 varchar2(15),
4 col3 number,
5 newcol number)
6 /
Table created.
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=test1.ctl log=test1.log
SQL*Loader: Release 11.2.0.1.0 - Production on Mon May 6 10:46:44 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
SCOTT@orcl_11gR2> select * from onecol_onerow
2 /
NEWCOL
201303
1 row selected.
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=test2.ctl log=test2.log
SQL*Loader: Release 11.2.0.1.0 - Production on Mon May 6 10:46:45 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 4
SCOTT@orcl_11gR2> select * from test_tab
2 /
COL1 COL2 COL3 NEWCOL
santiago producto1 100 201303
santiago producto2 200 201303
valparais producto1 400 201303
valparais producto3 900 201303
4 rows selected. -
Converting the comma seperator value format
i am getting the content of a table in a internal table with comma separator value format, dynamically by using dfies table i am getting the header of the table, and displaying it in the output, now my query is that the content of the data which i am getting in a itab having only one field of type string
data : begin of itab occurs 0,
data1 type string,
end of itab.
some where they were concatenating the content of the data and storing it inthe itab, now i want the content of the itab should be displayed corresponding to there header in the outputHi Santosh,
You can remove the commas from the record by using the REPLACE command as below -
LOOP AT itab.
DO.
REPLACE ',' WITH '' INTO itab-data1.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
Reward points if found useful...!
Cheers
Abhishek -
How to update person or group column with peopleeditor control values
Hi,
I have created custom aspx page and added "PeopleEditor" control(can select multiple users) in that page. Now I am trying to update person or group column with peopleeditor control values.I am not getting any error if I select single user
in PeopleEditor control but getting error if I select more than one user.
UpdateItem(listItem, "ListColumnName",
listItem.ParentList.ParentWeb.EnsureUser(peopleeditorId.CommaSeparatedAccounts));
Can anybody help me out to resolve the issue?
Thank you in advance!!!
AA.First get all the users/groups from the PeapleEditor by using PeapleEditor.ResolvedEntities
foreach (PickerEntity pickerEntity in peopleEditor.ResolvedEntities)
SPPrincipalType principalType = (SPPrincipalType)Enum.Parse(typeof(SPPrincipalType), pickerEntity.EntityData["PrincipalType"].ToString());
if (principalType == SPPrincipalType.User || principalType == SPPrincipalType.SecurityGroup)
string loginName = pickerEntity.Key;
//your code here
else if (principalType == SPPrincipalType.SharePointGroup)
string groupName = pickerEntity.Key;
//your code here
Add all the users/groups in an instance of SPFieldUserValueCollection
and then update your list item.
SPFieldUserValueCollection users = new SPFieldUserValueCollection();
users.Add(new SPFieldUserValue(web,user.ID,user.Name));
item["YourUserColumn"] = users;
item.Update(); -
Show row/column with empty dimension values.
I have 2 columns where 1 column is dimension and 1 column is measure. I need to hide the row when the dimension is empty.
What I did is at the block I UN-TICK "Show row/column with empty dimension values". But it didnt works.
Thanks.click on the block and add a filter with condition dimension isnotnull. this will eliminate the dimension rows with empty values.
Thanks,
karthik -
I hav an internal table . I want to download the data using GUI_DOWNLOAD with comma seperator. But condition is condition is i hav to convert the data into CSV format and then download.
How can i do this and send me th coding for exampleFor comma separation ,
report zcsv.
data: lt_poll type table of ypoll.
data: ls_poll type ypoll.
Changes made here
types: begin of ty_singlerow,
rowdata type string,
end of ty_singlerow.
data: lt_singlerow type table of ty_singlerow.
data: ls_singlerow type ty_singlerow.
Changes ends here
select *
from ypoll
into table lt_poll.
Changes made here
loop at lt_poll into ls_poll.
concatenate ls_poll-mandt
ls_poll-POLLID
ls_poll-TEAM
ls_poll-INITIATOR
ls_poll-DESCRIPTION
ls_poll-APPROVED
ls_poll-INITIATED_DATE
ls_poll-END_DATE
ls_poll-WINNER
into ls_singlerow-rowdata
separated by ','.
append ls_singlerow to lt_singlerow.
clear ls_singlerow.
endloop.
Changes ends here
call method cl_gui_frontend_services=>gui_download
exporting
BIN_FILESIZE =
filename = 'RESULTS_POLL.txt'
FILETYPE = 'ASC'
APPEND = SPACE
WRITE_FIELD_SEPARATOR = SPACE
HEADER = '00'
TRUNC_TRAILING_BLANKS = SPACE
WRITE_LF = 'X'
COL_SELECT = SPACE
COL_SELECT_MASK = SPACE
DAT_MODE = SPACE
CONFIRM_OVERWRITE = SPACE
NO_AUTH_CHECK = SPACE
CODEPAGE = SPACE
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = SPACE
TRUNC_TRAILING_BLANKS_EOL = 'X'
IMPORTING
FILELENGTH =
changing
data_tab = lt_singlerow
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
NOT_SUPPORTED_BY_GUI = 22
ERROR_NO_GUI = 23
others = 24
if sy-subrc <> 0.
write 'Unsuccessful'.
endif. -
How to seperate the data with comma seperator ??
Hi,
How to seperate the data with comma seperator ??
E.g i havea row like
Userid,number of days,Total Records
user1,10,100000
So,i will get 10,10000 in the same field and i need to seperate 10 and 10000 so what is the abap function for that
Prafflike this ...
SPLIT field AT ',' INTO
userid
days
records.
is this what you need?
Mike -
Column should display comma seperated value.
Hi All,
Iam working on Reports6i.
In my data model i have a query which gives some product names(only one column), i need to display those product names with a comma seperator.
Just like Product1,Product2,....
Can anybody guide me as this is very urgent.
Thanks in Advance
Chinni.something like this ?
WITH DATA AS (SELECT 'X' product,1 order_id FROM DUAL
UNION ALL
SELECT 'Y' product,1 order_id FROM DUAL
UNION ALL
SELECT 'Z' product,1 order_id FROM DUAL
UNION ALL
SELECT 'XX' product,2 order_id FROM DUAL
UNION ALL
SELECT 'YY' product,2 order_id FROM DUAL
UNION ALL
SELECT 'ZZ' product,2 order_id FROM DUAL
SELECT LTRIM(sys_connect_by_path(product,','), ',') PRODUCTS
FROM (SELECT product,
order_id,
row_number() OVER (partition by order_id order by product) RN,
count(product) OVER (partition by order_id) MAXROW
FROM data)
WHERE RN=MAXROW CONNECT BY PRIOR RN+1=RN
AND PRIOR ORDER_ID=ORDER_ID START WITH RN=1 -
Inserting comma seperated values
I created a stored procedure that creates an order_id. Using this id, the products and their pricetag are inserted. Hereafter the garnishes are inserted for each product.
Creating an order id and inserting the products and their pricetag are working. The problem is at the inserting of garnishes.
The data is received by parameters, and I have also created a user defined type: where garnishId holds the comma seperated ids.
CREATE TYPE [dbo].[ppg] AS TABLE(
[ProductId] [int] NULL,
[PriceId] [int] NULL,
[garnishId] [VARCHAR](MAX) NULL
this is the stored procedure:
ALTER PROCEDURE [dbo].[sp_create_order]
(@userId uniqueidentifier, @productPriceGarnishes dbo.ppg READONLY, @comment varchar(250))
AS
BEGIN
DECLARE @orderId int
DECLARE @orderDetailId int
INSERT INTO orders (user_id, confirmed,comment) values(@userId,0,@comment);
--Select last inserted PK
SELECT @orderId=SCOPE_IDENTITY()
-- insert products and price tag using @orderId
INSERT INTO order_detail (order_id, product_id,price_id)
SELECT @orderId, p.ProductId,
p.PriceId
FROM @productPriceGarnishes p
SELECT @orderDetailId=SCOPE_IDENTITY()
-- insert garnishes using the orderDetailId
INSERT INTO order_detail_garnish (order_detail_id,garnish_id)
SELECT @orderDetailId, (SELECT * FROM SplitDelimiterString(p.garnishId))
FROM @productPriceGarnishes p
END
RETURN @orderId
I found a function that splits the string by a delimiter in this website:
http://www.codeproject.com/Tips/586395/Split-comma-separated-IDs-to-ge
Where you can retrieve the ids by this query:
(SELECT * FROM SplitDelimiterString(p.garnishId)
The problem is that I don't know how to add these ids with their corresponding orderDetailId, after each product is added.Unfortunately it appears you assume too much. Presumably the reason you chose to define @productPriceGarnishes as a table is to support the creation of multiple rows. And you use these rows to insert into the order_detail table which has an identity
column as the primary key (again, presumably). So the question then becomes how do you get the identity values for ALL of the inserted rows? You can't do that with SCOPE_IDENTITY - your code currently is designed with the assumption that there
is only one row to be inserted. To work around that limitation you need to use the output clause (examples can be found by searching).
Next comes another problem. How do you know which identity value is assigned to which row of your table variable during the insert? You need some sort of natural key to associate the inserted rows with the rows in the table variable. Do
you have one? Before you think you do, you need to think about what restrictions are placed on the content of the table variable (if any). Is it possible to have multiple rows with the same values for ProductId and PriceId? Do not assume
- you need to be certain that this is or is not a possibility.
Assuming that the rows are unique (which simplifies things greatly), you associate the inserted order_detail rows to the table variable via something like:
select ... from @ins_detail as ins inner join @productPriceGarnishes as ppg
on ins.ProductId = ppg.ProductId and ins.PriceId = ppg.PriceId
Note that @ins_detail is a table variable that you would declare and populate via the output clause. It will contain the identity values for each row that you inserted. With that, you can then generate the rows that you need to insert into the garnish
table by applying the results of your splitter function. Which is a step that I'll skip for now since you have much reading and work to do.
Now some last comments. I am suspicious of a column named PriceId. That is not a good sign - price is an attribute of something and not the basis of a relationship between tables. The use of identity columns (especially as primary keys)
can be a problem - and this is one good example. Based on what I've just written and its assumptions, the natural key for order_detail is (order_id, product_id, price_id) - why do you need an identity column? Again, searching will find past
discussions about identity columns and their usage.
Maybe you are looking for
-
Need some help... running out of time
Hope everyone is well... I have a G5 dual 2.5 running 10.3.9... running final cut 5.0.4... I am having a **** of a time being able to capture my hd media... some days it works and some days it dosen't. deviceses used: sony hd cameras hdr-fx1 to shoot
-
Has anyone else had issues with phone network being unavailable on iPhone 4 since updating to iOS 5.0.1? My iPhone 4 is continually searching for a network and does not find AT&T, my provider. I swapped SIM cards with another iPhone 4 running ios 4 a
-
HP Photosmart C4480 through Time Capsule
I have a Vista machine and my wife has a Macbook Pro she just got. We both wanted to share a wireless printer so the guy at the apple store suggested we get the Time Capsule and the HP Photosmart (actually we got the 100 off printer deal so we got th
-
MacBook Pro acting weird at startup
Hi, First of all thank you for reading this, it's quite a long story. And sorry for any grammatical mistakes, I'm Dutch. Summary My MBP suddenly has been acting really weird: kernel_task eating 150-200% of the CPU which caused a super slow MBP, power
-
Excuse me if I dont speak very very well in english. I'm from Québec. Go to the important thing my ipod doesn't want open the a symbol appears in the screen it a USB plug with a arrows pointing the Itunes logo