Hi Guys,
Given the table and rows on it below:
MYTABLE
-----------------
CODE varchar(30)
NAME varchar(100
DESCRIPTION(300)
-----------------
CODE NAME DESCRIPTION
----------------------------------------------------------------------------------------------------------------------------------------------
null Cozaar Cozaar Tab 50 mg
null Cozaar Cozaar Tab 100 mg
null Cozaar Cozaar Pulv og væske til mikst 2,5 mg/ml
null Cozaar Cozaar Tab 12,5 mg
null Cozaar Cozaar Tab 50 mg
null NatriumhydrogenkarbonatBraunplus Nycoplus calcium m/K & D3-vitamin Tab 75 mikrog/5 mikrog/250 mg
null Skelan Skelan 500 mg
null Detox Detox 100mg
null Skelan Skelan 500 mg
null NatriumhydrogenkarbonatBraunplus Nycoplus calcium m/K & D3-vitamin Tab 75 mikrog/5 mikrog/500 mg
null BenzylpenicillinVMpanpharmaSA Benzylpenicillin VM panpharma SA Pulv og væske til inf væske 1,2 g
----------------------------------------------------------------------------------------------------------------------------------------------
If duplicate NAME, will then check if duplicate description.
If description is not duplicate then update CODE = 'GMD_' + upper(NAME) + '1'... and so on (but since CODE is varchar(30), substr NAME to fit in the CODE field
if duplicate NAME and DESCRIPTION then delete duplicate row(s)
If unique then CODE = 'GMD_' || upper(substr(name,1,25));
Final rows after the changes will be like this:
CODE NAME DESCRIPTION
----------------------------------------------------------------------------------------------------------------------------------------------
GMD_COZAAR1 Cozaar Cozaar Tab 50 mg
GMD_COZAAR2 Cozaar Cozaar Tab 100 mg
GMD_COZAAR3 Cozaar Cozaar Pulv og væske til mikst 2,5 mg/ml
GMD_COZAAR4 Cozaar Cozaar Tab 12,5 mg
GMD_SKELAN Skelan Skelan 500 mg
GMD_DTOX Detox Detox 100mg
GMD_NATRIUMHYDROGENKARBONAT1 NatriumhydrogenkarbonatBraunplus Nycoplus calcium m/K & D3-vitamin Tab 75 mikrog/5 mikrog/250 mg
GMD_NATRIUMHYDROGENKARBONAT2 NatriumhydrogenkarbonatBraunplus Nycoplus calcium m/K & D3-vitamin Tab 75 mikrog/5 mikrog/500 mg
GMD_BENZYLPENICILLINVMPANPHA BenzylpenicillinVMpanpharmaSA Benzylpenicillin VM panpharma SA Pulv og væske til inf væske 1,2 g
----------------------------------------------------------------------------------------------------------------------------------------------
Can anybody suggest a query to do this?
TIA
Yorge
Given the table and rows on it below:
MYTABLE
-----------------
CODE varchar(30)
NAME varchar(100
DESCRIPTION(300)
-----------------
CODE NAME DESCRIPTION
----------------------------------------------------------------------------------------------------------------------------------------------
null Cozaar Cozaar Tab 50 mg
null Cozaar Cozaar Tab 100 mg
null Cozaar Cozaar Pulv og væske til mikst 2,5 mg/ml
null Cozaar Cozaar Tab 12,5 mg
null Cozaar Cozaar Tab 50 mg
null NatriumhydrogenkarbonatBraunplus Nycoplus calcium m/K & D3-vitamin Tab 75 mikrog/5 mikrog/250 mg
null Skelan Skelan 500 mg
null Detox Detox 100mg
null Skelan Skelan 500 mg
null NatriumhydrogenkarbonatBraunplus Nycoplus calcium m/K & D3-vitamin Tab 75 mikrog/5 mikrog/500 mg
null BenzylpenicillinVMpanpharmaSA Benzylpenicillin VM panpharma SA Pulv og væske til inf væske 1,2 g
----------------------------------------------------------------------------------------------------------------------------------------------
If duplicate NAME, will then check if duplicate description.
If description is not duplicate then update CODE = 'GMD_' + upper(NAME) + '1'... and so on (but since CODE is varchar(30), substr NAME to fit in the CODE field
if duplicate NAME and DESCRIPTION then delete duplicate row(s)
If unique then CODE = 'GMD_' || upper(substr(name,1,25));
Final rows after the changes will be like this:
CODE NAME DESCRIPTION
----------------------------------------------------------------------------------------------------------------------------------------------
GMD_COZAAR1 Cozaar Cozaar Tab 50 mg
GMD_COZAAR2 Cozaar Cozaar Tab 100 mg
GMD_COZAAR3 Cozaar Cozaar Pulv og væske til mikst 2,5 mg/ml
GMD_COZAAR4 Cozaar Cozaar Tab 12,5 mg
GMD_SKELAN Skelan Skelan 500 mg
GMD_DTOX Detox Detox 100mg
GMD_NATRIUMHYDROGENKARBONAT1 NatriumhydrogenkarbonatBraunplus Nycoplus calcium m/K & D3-vitamin Tab 75 mikrog/5 mikrog/250 mg
GMD_NATRIUMHYDROGENKARBONAT2 NatriumhydrogenkarbonatBraunplus Nycoplus calcium m/K & D3-vitamin Tab 75 mikrog/5 mikrog/500 mg
GMD_BENZYLPENICILLINVMPANPHA BenzylpenicillinVMpanpharmaSA Benzylpenicillin VM panpharma SA Pulv og væske til inf væske 1,2 g
----------------------------------------------------------------------------------------------------------------------------------------------
Can anybody suggest a query to do this?
TIA
Yorge