MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

To Generate SQL based on where clause.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
sendhil
Beginner


Joined: 06 Sep 2006
Posts: 17
Topics: 6

PostPosted: Thu Jan 25, 2007 6:52 am    Post subject: To Generate SQL based on where clause. Reply with quote

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
View user's profile Send private message Send e-mail
sendhil
Beginner


Joined: 06 Sep 2006
Posts: 17
Topics: 6

PostPosted: Thu Jan 25, 2007 6:55 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Jan 25, 2007 8:12 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
sendhil
Beginner


Joined: 06 Sep 2006
Posts: 17
Topics: 6

PostPosted: Thu Jan 25, 2007 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Jan 25, 2007 9:08 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group