| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |
|

08-16-11, 11:21
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
|
putting value NULL in column need help
|
|
Hi,
can you help me on my stored procedure how can i make a stored procedure using data studio that will display value NULL in the column if there is no matched in other table,example customer_table and order_table,if the customer has no order in order_table the customer name will be change to NULL...Thank you in advance.
|
|

08-16-11, 11:34
|
|
Registered User
|
|
Join Date: Jan 2003
Posts: 3,575
|
|
Use a CASE statement.
Andy
|
|

08-16-11, 11:59
|
|
Super Moderator
|
|
Join Date: Aug 2001
Location: UK
Posts: 4,534
|
|
|
|
Outer joins ?
Quote:
Originally Posted by jemz
Hi,
can you help me on my stored procedure how can i make a stored procedure using data studio that will display value NULL in the column if there is no matched in other table,example customer_table and order_table,if the customer has no order in order_table the customer name will be change to NULL...Thank you in advance.
|
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
|
|

08-16-11, 12:14
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
sir in using the case,correct me if i am wrong
case customer_name
when customer_id=order_id THEN 'NULL'
ELSE
END AS CUSTOMER_NAME
is this correct sir?i am confuse in the case...please help me
|
|

08-16-11, 12:19
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by sathyaram_s
Outer joins ?
|
Hi,thank you for the reply but how can i display null to the customer name or to change it null all the customer name if there is no order in the order_table?Thank you in advance
|
|

08-16-11, 12:32
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
Quote:
case customer_name
when customer_id=order_id THEN 'NULL'
ELSE
END AS CUSTOMER_NAME
|
You should see syntax diagram in this more carefully.
CASE expression - IBM DB2 9.7 for Linux, UNIX, and Windows
1) Are you using searched-when-clause or simple-when-clause?
They can't be intermixed.
2) ELSE should be followed by NULL or result-expression.
Quote:
Code:
CASE expression
case-expression
|--CASE--+-searched-when-clause-+------------------------------->
'-simple-when-clause---'
.-ELSE NULL---------------. (1)
>--+-------------------------+--END-----------------------------|
'-ELSE--result-expression-'
searched-when-clause
.-----------------------------------------------------.
V |
|----WHEN--search-condition--THEN--+-result-expression-+-+------|
'-NULL--------------'
simple-when-clause
.-----------------------------------------------.
V |
|--expression----WHEN--expression--THEN--+-result-expression-+-+--|
'-NULL--------------'
|
3) "customer_id=order_id" is a search condition(simplest form of a condition which contains only a predicate) and not an expression.
http://publib.boulder.ibm.com/infoce.../r0000754.html
http://publib.boulder.ibm.com/infoce.../r0000746.html
Quote:
Code:
Search conditions
search-condition
|--+-----+--+-predicate--+-------------------------------+-+---->
'-NOT-' | '-SELECTIVITY--numeric-constant-' |
'-(search-condition)---------------------------'
.------------------------------------------------------------------------.
V |
>----+--------------------------------------------------------------------+-+--|
'-+-AND-+--+-----+--+-predicate--+-------------------------------+-+-'
'-OR--' '-NOT-' | '-SELECTIVITY--numeric-constant-' |
'-(search-condition)---------------------------'
|
Quote:
Code:
Basic predicate
>>-expression--+- = ------+----expression----------------------><
| (1) |
+- <> -----+
+- < ------+
+- > ------+
| (1) |
+- <= -----+
| (1) |
'- >= -----'
|
|
Last edited by tonkuma; 08-16-11 at 12:52.
Reason: Add 3).
|

08-16-11, 13:09
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by tonkuma
|
Hi,Thank you for this,but what if i have 4 tables how do i use the case?
|
|

08-16-11, 13:17
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by tonkuma
|
Hello here is i want the output
Quote:
order_id order_unit customer_name
0001 1pc John Mayer
0002 2pcs Steve Jobs
0003 3pcs Karl Debb
Shane Karl
Michael Shane
|
since Shane Karl and Michael Shane have no order there names will be change to NULL.is this possible?Thank you in advance and I am hoping for your positive response.
|
Last edited by jemz; 08-17-11 at 01:08.
|

08-16-11, 13:20
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
Quote:
|
what if i have 4 tables how do i use the case?
|
Too simple description to understand what you want to do.
Please give me sample data and expected result.
You should supply at least three or more rows for each of 4 tables.
|
|

08-16-11, 14:09
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by tonkuma
Too simple description to understand what you want to do.
Please give me sample data and expected result.
You should supply at least three or more rows for each of 4 tables.
|
Hi , please find the attachment. I also wrote the problem.please help me sir.Thank you in advance and more power to you always.
|
Last edited by jemz; 08-18-11 at 22:47.
|

08-16-11, 19:20
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
Quote:
Hi sir, please find the attachment. I also wrote the problem.please help me sir.Thank you in advance and more power to you always.
Attached Files
MY.zip (2.1 KB, 2 views)
|
I couldn't see the attached file.
Quote:
|
Errors were found in .ZIP file. attempt to fix
|
If I choose Y, repeated same error.
|
|

08-17-11, 00:37
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by tonkuma
I couldn't see the attached file.
If I choose Y, repeated same error.
|
Okay, I attached again the zip file.I hope you can get the attachment.Thank you in advance.
|
Last edited by jemz; 08-18-11 at 22:48.
|

08-17-11, 08:31
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
I couldn't see the newly attached file, too.
May be something wrong with my setting or usage of unzip program in my laptop.
|
|

08-17-11, 11:34
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 76
|
|
Quote:
Originally Posted by tonkuma
I couldn't see the newly attached file, too.
May be something wrong with my setting or usage of unzip program in my laptop.
|
what about this,try this one...I hope you can get now.Thank you in advance.more power to you always
Attachment 12056
|
Last edited by jemz; 08-18-11 at 22:49.
|

08-17-11, 11:43
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
I couldn't see the file, too
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|