for   
Save 
Save 
   Join IIUG  

Informix News
29 April 08 - IntelligentEnterprise.com - IBM Informix Upgrade Enhances Clustering, Database Management... Read
29 April 08 - itweek.com - IBM 'Cheetah 2' mauls data costs... Read
28 April 08 - eWeek.com - IBM Uncages Cheetah 2 Data Server... Read
28 April 08 - CNNMoney.com - IBM Helps Clients Reduce Data Management Costs With New Informix Dynamic Server... Read
09 April 08 - CNNMoney.com - MediaSpan Embeds IBM Informix Dynamic Server Software for Delivering News to Print, Web and Wireless Devices... Read
08 April 08 - IT-Director.com - Informix seeks developers... Read
18 February 08 - marketwire.com - Icarus Studios Partners With IBM to Upgrade Performance, Availability for Its Online Games... Read
17 January 08 - eWeek.com - IBM Adds Mac Support to IDS for Higher Education... Read
17 January 08 - informationweek.com - Lotus Notes For iPhone Signals Closer Ties Between IBM, Apple... Read
16 January 08 - marketwire.com - IBM Informix Dynamic Server to Deliver Support for Mac OS X... Read
16 January 08 - internetnews.com - IBM's IDS to Support Mac Platform... Read
28 June 07 - REG Developer - IBM and Informix tie down Cheetah... Read
27 June 07 - CBRonline.com - IBM corrects its own Informix customer figures... Read
14 June 07 - vnunet.com - IBM changes spots with Informix 'Cheetah' database... Read
14 June 07 - eChannelLine - IBM expands scope for IDS... Read
14 June 07 - Resellernews - IBM: Informix database alive and kicking... Read
13 June 07 - DB2 Magazine - Cheetah is now out of the gate... Read
12 June 07 - IBM - IDS 11 release announcement (pdf)... Read
12 June 07 - ChannelWeb Network - IBM Uncages IDS 11, Aka Cheetah, Database... Read
12 June 07 - eWeek.com - IBM's 'Cheetah' Ready to Pounce... Read
12 June 07 - InformationWeek - IBM Unleashes 'Cheetah' Database... Read
12 June 07 - WebWire - IBM Strengthens Database Portfolio With New Informix Dynamic Server... Read
12 June 07 - Intelligent Enterprise - IBM Unveils Informix Upgrade... Read
12 June 07 - ComputerWeekly.com - IBM's Cheetah IDS makes leap to better data centre clustering... Read
12 June 07 - ebiz - IBM Unveils Next Generation Informix Dynamic Server... Read
12 June 07 - computerworld.com - Will 'Cheetah' help IBM's Informix chase down market share?... Read
12 June 07 - Internetnews.com - No Data Can Outrun This 'Cheetah'... Read
12 June 07 - de.internet.com - IBM neuer Datenbank-Server mit Codenamen Cheetah ist fertig... Read
12 June 07 - verifox.de - IBM stärkt Datenbank-Portfolio mit neuem Informix Dynamic Server... Read
12 June 07 - golem.de - Informix 11 vorgestellt... Read
12 June 07 - Computerwoche.de - IBM stellt neue Informix-Version vor... Read
12 June 07 - IBM.de - IBM stärkt Datenbank-Portfolio mit neuem Informix Dynamic Server... Read
12 June 07 - Heise - IBM gibt Informix 11 frei... Read
25 May 07 - Taiwan.CNET.com - Local Taiwan Informix user group established... (Chinese language) ... Read
18 May 07 - ChannelWeb Network - IBM Musters Partners For Cheetah Release... Read
18 May 07 - eWeek.com - IBM Looks to 'Cheetah' to Speed Up Blade Servers... Read
7 May 07 - DB2 Magazine - SQL Shortcuts - Use these tricks to generate IDS SQL scripts... Read

Previous news items
 

Home Member Area About IIUG


Resources
IIUG Insider
IIUG Hotspots
IBM-Informix Links
IIUG RSS Feeds
Software Repository
Informix Products
Online Resources
Informix Library
Informix Books
IIUG Banners
Discussion
Technical SIGs
Non-technical
Other Discussion
Community
Events
Webcasts/Chat w Lab
IIUG TV
IIUG Sponsors
Informix Business Directory
IIUG Press Partners
Local User Groups
Job Board
Fun Stuff

[ Post Response ] [ Return to Index ] [ Read Prev Msg ] [ Read Next Msg ]

Informix Forum

Re: Why does this set values to null?

Posted By: Jonathan Leffler
Date: Sunday, 26 March 2006, at 3:57 a.m.

On 3/25/06, informix-forum@iiug.org wrote:
> #77: Why does this set values to null? (JOHN SAYRE)
> <http://www.iiug.org/forums/informix-forum/index.cgi?rev=77>

>
> I am attempting to add current day information to ytd and mtd fields in a
> table of customers. I have defaulted the numeric fields to 0 in the table
> definition.
>
> If I run query one, those customers with sales that day will have values in
> the
> ty_sls field. But this will update the rest of the customers who have no sales
> that day back to null
>
> update loy_cust_report set ty_sls = nvl(ty_sls,0) + ((select
> nvl(sum(transaction_amount),0)
> from loy_trans_header
> where loy_cust_report.customer_id = loy_trans_header.customer_id
> and date(loy_trans_header.transaction_date) = today - 1
> group by loy_cust_report.customer_id))
> ;
>
> This will flip-flop and return the nulls to legitimate values and make any
> custs with no sales two days ago null
[...]
> As far as I can see, the query should only find the customers where there is a
> match between the two tables on the day and ignore the rest.
>
> What am I missing?

A WHERE clause on the UPDATE, as opposed to the sub-select.

You didn't specify which rows you wanted updated, so it applies the
update to every row in the table - as is routine and expected. For
those where the sub-select does not find matching data, you get null.
It's a standard trap, in both senses of the term: people fall into it
regularly, and it is the behaviour required by the SQL standard.

So, add a WHERE clause to the UPDATE that identifies correctly those
rows that need to be updated. Something along the lines of:

WHERE customer.id IN (SELECT h,customer_id FROM loy_trans_header AS h

WHERE DATE(h.transaction_date) = TODAY - 1)

I'm left wondering what the type of
'loy_trans_header.transaction_date' is that you need to convert it to
DATE; I guess it is a DATETIME field that includes a time component.
The code also gives you problems if you ever have a machine crash that
means you miss one day's processing and you need to retrospectively
run the update. I'd look to replace the TODAY - 1 part with a
reference date as a parameter, and set that date parameter to TODAY -
1 for the normal case, but to whatever value was necessary to run it
retrospectively.

--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/

[ Post Response ] [ Return to Index ] [ Read Prev Msg ] [ Read Next Msg ]

Informix Forum is maintained by Administrator with WebBBS 5.12.

©2001 - 2007 International Informix Users Group.   All rights reserved.     Terms of use    
*** Powered By IBM Informix Dynamic Server V10.00 ***