Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to set default value to column ?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
rajandhla

Active User


Joined: 18 Oct 2005
Posts: 182
Location: Luton UK

PostPosted: Thu Jul 26, 2007 6:49 pm    Post subject: How to set default value to column ?
Reply with quote

Hi Guys,

Can you please let me know how to set default value to a column.

Select <C1>, <C2> from table1.

I want to set default value to column c2 irrespective of the data the table contains.

Regards,
JR
Back to top
View user's profile Send private message

sandeep1dimri

New User


Joined: 30 Oct 2006
Posts: 76

PostPosted: Thu Jul 26, 2007 6:59 pm    Post subject:
Reply with quote

Select <C1>, 'default value' from table1.
Back to top
View user's profile Send private message
rajandhla

Active User


Joined: 18 Oct 2005
Posts: 182
Location: Luton UK

PostPosted: Thu Jul 26, 2007 7:04 pm    Post subject: Re: How to set default value to column ?
Reply with quote

Cheers JR.....
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Jul 27, 2007 2:25 am    Post subject:
Reply with quote

Hello,

Just to make sure we are all thinking the same way. . . .

This
Quote:
Select <C1>, 'default value' from table1.
will force the default value into the result from the execution of that select.

The data in the table will not contain the "default value" after that select is executed. A subsequent "SELECT C1, C2 FROM TABLE1" will not return the "defalut value", it will return whatever values were in C2 in the table.
Back to top
View user's profile Send private message
rajandhla

Active User


Joined: 18 Oct 2005
Posts: 182
Location: Luton UK

PostPosted: Fri Jul 27, 2007 10:06 am    Post subject: Re: How to set default value to column ?
Reply with quote

Hi,

Is it possible to set default value for the column in the cursor. And i want the default value in the corresponding value in the host variable after fetch executed?

Regards,
Jr
Back to top
View user's profile Send private message
sundar28

New User


Joined: 30 Jul 2005
Posts: 12
Location: Mysore

PostPosted: Fri Jul 27, 2007 1:13 pm    Post subject: Re: How to set default value to column ?
Reply with quote

Rajandhla,

Clarify your question!

Quote:
How to set default value to column ?
icon_exclaim.gif
is not the question for the answers you got.

Shall I restate your question as
How to get a common value in place of one column for all the result rows? icon_question.gif

Quote:
Is it possible to set default value for the column in the cursor

Shall I restate your question as
Is it possible to set default value for the column in a result table fetched using cursor

icon_idea.gif It is possible. The query format is the same as sandeep1dimri had given.

icon_arrow.gif Note: A common value not default value: "Default" is to fill up an absence of a requisite data

Quote:
And i want the default value in the corresponding value in the host variable after fetch executed?


icon_mad.gif But why? You can initialize your host variable with that default value before fetch. For this simple purpose, do not change your query to give DB2 an extra task??
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Jul 27, 2007 8:06 pm    Post subject:
Reply with quote

So you want to fetch the default value in your cursor and also push that default value back to the actual database?

The first solution give will set the value in your cursor only. If you want to push that value back to the database, you need to execute an UPDATE to push the value back to the table.

Use your SELECT cursor to read the values out to working storage with your default value for COLUMN2. Then use your UPDATE command to change the actual table.

Code:

*Declare SELECT cursor to have this SQL
SELECT COL1,
       'DefaultValue'
FROM TABLE1
WHERE COL1 = :WS-COL1Lookup

*Open the cursor
EXEC SQL FETCH select-cursor-name
     INTO :WS-COL1,
         :WS-COL2
END-EXEC.

EXEC SQL
   UPDATE TABLE1
   SET COL2 = :WS-COL2
   WHERE COL1 = :WS-COL1
END-EXEC.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Jul 27, 2007 8:07 pm    Post subject:
Reply with quote

ignore the update-cursor-name I don't know what I was thinking there.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DFSORT - Overriding default option TU... Steve Ironmonger DFSORT/ICETOOL 3 Tue Apr 04, 2017 3:54 pm
This topic is locked: you cannot edit posts or make replies. DB2 query Using Recursion, Converting... smilewithashu2 DB2 3 Tue Jan 03, 2017 12:50 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 6 Sun Nov 06, 2016 8:11 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Add system date inside of a PS file a... pramitdas DFSORT/ICETOOL 5 Sun Aug 28, 2016 12:06 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us