IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to set default value to column ?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
Reply with quote

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

Moderator Emeritus


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

PostPosted: Fri Jul 27, 2007 2:25 am
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
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: 11
Location: Mysore

PostPosted: Fri Jul 27, 2007 1:13 pm
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts Running a Job with the Default User ID JCL & VSAM 2
No new posts first column truncated in search result IBM Tools 13
Search our Forums:

Back to Top