sql - Inserting multiple rows into a Company - Parameter - Value table -


alright, let's have database table named "company_parameters" looks (the first 2 columns keys):

comp_id | param_name | param_value       | parameter 1| 10       | sample_ind | y    b    | parameter 1| 20    b    | sample_ind | n 

i insert new parameter, let's parameter 2 table, every company id in table. not know company id expect, since client can have company id want, 1 client might have company ids 1,2,3,4 , might have a,b,c,d, etc. use series of update scripts store on repository time update database. i've asked around , 1 of rare (only) tables unique every client, try anyway.

i've been working databases less year , don't know start problem this. guess use select statement find unique comp_ids , insert row every 1 of them.

your appreciated.

-asaf

insert company_parameters     (comp_id, param_name)     select distinct cp.comp_id, 'parameter 2'         company_parameters cp; 

if wanted careful, extend query make sure new parameter doesn't exist.

insert company_parameters     (comp_id, param_name)     select distinct cp.comp_id, 'parameter 2'         company_parameters cp         not exists(select 1                              company_parameters cp2                              cp2.comp_id = cp.comp_id                                  , cp2.param_name = 'parameter 2'); 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -

delphi - How to convert bitmaps to video? -