View previous topic :: View next topic |
Author |
Message |
sendhil Beginner
Joined: 06 Sep 2006 Posts: 17 Topics: 6
|
Posted: Thu Jan 25, 2007 6:52 am Post subject: To Generate SQL based on where clause. |
|
|
Hi,
We are trying to generate update SQLs based on a sql condition.
SELECT
'UPDATE TABLEA',
'SET COL1 = ''X''',
'WHERE COL2=',
COL2,
';'
'COMMIT;'
FROM TABLEA
WHERE COL3= 'xxxxxx' ;
We got the output of this select statement as follows.
UPDATE TABLEA SET COL1 = 'X' WHERE COL2= COL2value1; COMMIT
UPDATE TABLEA SET COL1 = 'X' WHERE COL2= COL2value2; COMMIT
UPDATE TABLEA SET COL1 = 'X' WHERE COL2= COL2value3; COMMIT
UPDATE TABLEA SET COL1 = 'X' WHERE COL2= COL2value4; COMMIT
etc...
We need a colon before and after the COL2value* so that we can rerun those update statements.(These are the variables that filled up the places as a result of the select statement)
I am not sure how to achieve this. |
|
Back to top |
|
 |
sendhil Beginner
Joined: 06 Sep 2006 Posts: 17 Topics: 6
|
Posted: Thu Jan 25, 2007 6:55 am Post subject: |
|
|
Sorry ,
We need a apostrophe before and after the COL2value* so that we can rerun those update statements.(These are the variables that filled up the places as a result of the select statement)
I am not sure how to achieve this. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu Jan 25, 2007 8:12 am Post subject: |
|
|
sendhil,
Try this
Code: |
SELECT CHAR('UPDATE TABLEA')
,CHAR(' SET COL1 = ''X''')
,CHAR(' WHERE COL2 = ')
,CHAR('''')
,COL2
,CHAR('''')
,CHAR(';')
,CHAR('COMMIT;')
FROM TABLEA
WHERE COL3= 'xxxxxx' ;
|
This will produce the result as follows
Code: |
UPDATE TABLEA SET COL1 = 'X' WHERE COL2= 'COL2value1'; COMMIT
UPDATE TABLEA SET COL1 = 'X' WHERE COL2= 'COL2value2'; COMMIT
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
sendhil Beginner
Joined: 06 Sep 2006 Posts: 17 Topics: 6
|
Posted: Thu Jan 25, 2007 9:06 am Post subject: |
|
|
Kolusu,
I have tried the above mentioned query .
The problem was i got extra spaces when i did that.
The output looked as below.
Code: |
UPDATE TABLEA SET COL1 = 'X' WHERE COL2= ' COL2value1 '; COMMIT
UPDATE TABLEA SET COL1 = 'X' WHERE COL2= ' COL2value2 '; COMMIT
|
Is this something to do with the settings? |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu Jan 25, 2007 9:08 am Post subject: |
|
|
sendhil,
That is only in SPUFI Display. Spufi automatically puts a space after each column selected. Try unload using the same query in batch and you will Not see the extra spaces.
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
|
|