dbTalk Databases Forums  

alternate approach to this sql

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss alternate approach to this sql in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
annecarterfredi@gmail.com
 
Posts: n/a

Default alternate approach to this sql - 10-02-2007 , 12:19 PM






My input data is csv file like this with '|' delimiter:
1|first
2|second
3|third
4|fourth
5|fifth

I need to load this into temp table for validation purposes...so I did
this:

with T (ID) as ( values '1|first','2|second','3|third','4|fourth','5|
fifth')
select substr(ID, 1,locate('|', ID)-1) as FIRST_COLUMN,
substr(ID, locate('|', ID)+1, length(ID)-locate('|', ID)) as
SECOND_COLUMN
from T

Is there better approach?
What is syntax for having more than one column in "with" clause, eg:
with T (ID, DESC) as ( values '1','2','3','4','5')
select ID, DESC from T -- where should I put DESC
('first','second','third','fourth','fifth') in "values" clause?


Reply With Quote
  #2  
Old   
annecarterfredi@gmail.com
 
Posts: n/a

Default Re: alternate approach to this sql - 10-02-2007 , 12:40 PM






On Oct 2, 1:19 pm, "annecarterfr... (AT) gmail (DOT) com"
<annecarterfr... (AT) gmail (DOT) com> wrote:
Quote:
My input data is csv file like this with '|' delimiter:
1|first
2|second
3|third
4|fourth
5|fifth

I need to load this into temp table for validation purposes...so I did
this:

with T (ID) as ( values '1|first','2|second','3|third','4|fourth','5|
fifth')
select substr(ID, 1,locate('|', ID)-1) as FIRST_COLUMN,
substr(ID, locate('|', ID)+1, length(ID)-locate('|', ID)) as
SECOND_COLUMN
from T

Is there better approach?
What is syntax for having more than one column in "with" clause, eg:
with T (ID, DESC) as ( values '1','2','3','4','5')
select ID, DESC from T -- where should I put DESC
('first','second','third','fourth','fifth') in "values" clause?
I got it..I can use "values ('1','first')" in my query..



Reply With Quote
  #3  
Old   
Lennart
 
Posts: n/a

Default Re: alternate approach to this sql - 10-02-2007 , 11:11 PM



On Oct 2, 7:19 pm, "annecarterfr... (AT) gmail (DOT) com"
<annecarterfr... (AT) gmail (DOT) com> wrote:
Quote:
My input data is csv file like this with '|' delimiter:
1|first
2|second
3|third
4|fourth
5|fifth

I need to load this into temp table for validation purposes...so I did
this:

with T (ID) as ( values '1|first','2|second','3|third','4|fourth','5|
fifth')
select substr(ID, 1,locate('|', ID)-1) as FIRST_COLUMN,
substr(ID, locate('|', ID)+1, length(ID)-locate('|', ID)) as
SECOND_COLUMN
from T

Is there better approach?
import from f.csv of del modified by coldel0x7C insert into T

/Lennart



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.