Unix Technical Forum

a how can I do this in Informix question

This is a discussion on a how can I do this in Informix question within the Informix forums, part of the Database Server Software category; --> Hello, I have a problem in Informix that I need to solve. I have table Table ABC { Field1 ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 10:27 AM
Quetzalcoatl
 
Posts: n/a
Default a how can I do this in Informix question

Hello,

I have a problem in Informix that I need to solve.

I have table

Table ABC
{
Field1 integer,
Field2 char(5),
Insdate integer
}

What I want now is when an insert occurs on this table on the fields
(Field1 and Field2) that afterwards the fields Insdate is filled with
the date of today but stored as a number in the format YYYYMMDD.

Example:

Insert into ABC (Field1, Field2)
values (1, "Wim");

then should the query

Select * from ABC;

return:

Field1 Field2 Insdate
1 Wim 20051027

My collegue found how to do it in Oracle and now I want to prove it also
can be done in Informix. I hope. Else me and my big mouth :-)

So help me please.

Thanks,

Wim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 10:27 AM
scottishpoet
 
Posts: n/a
Default Re: a how can I do this in Informix question

The way to do this best in Informix is to redfine insdate as a DATE
datatype set a default for the column = TODAY

Set DBDATE = Y4MD



Quetzalcoatl wrote:
> Hello,
>
> I have a problem in Informix that I need to solve.
>
> I have table
>
> Table ABC
> {
> Field1 integer,
> Field2 char(5),
> Insdate integer
> }
>
> What I want now is when an insert occurs on this table on the fields
> (Field1 and Field2) that afterwards the fields Insdate is filled with
> the date of today but stored as a number in the format YYYYMMDD.
>
> Example:
>
> Insert into ABC (Field1, Field2)
> values (1, "Wim");
>
> then should the query
>
> Select * from ABC;
>
> return:
>
> Field1 Field2 Insdate
> 1 Wim 20051027
>
> My collegue found how to do it in Oracle and now I want to prove it also
> can be done in Informix. I hope. Else me and my big mouth :-)
>
> So help me please.
>
> Thanks,
>
> Wim


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-20-2008, 10:27 AM
Art S. Kagel
 
Posts: n/a
Default Re: a how can I do this in Informix question

Quetzalcoatl wrote:
> Hello,
>
> I have a problem in Informix that I need to solve.
>
> I have table
>
> Table ABC
> {
> Field1 integer,
> Field2 char(5),
> Insdate integer
> };


> What I want now is when an insert occurs on this table on the fields
> (Field1 and Field2) that afterwards the fields Insdate is filled with
> the date of today but stored as a number in the format YYYYMMDD.


How about this as just ONE way to do it:

create procedure create_abc_default_date() returning int
define result int;

select year(current) * 10000 + month(current) * 100 + day(current)
into result
from systables
where tabid = 1;

return result;
end procedure;

create trigger abc_ins for insert on abc
referencing new as rec
for each row
update abc set insdate = create_abc_default_date()
where field1 = rec.field1 and field2 = rec.field2;

Art S. Kagel

> Example:
>
> Insert into ABC (Field1, Field2)
> values (1, "Wim");
>
> then should the query
>
> Select * from ABC;
>
> return:
>
> Field1 Field2 Insdate
> 1 Wim 20051027
>
> My collegue found how to do it in Oracle and now I want to prove it also
> can be done in Informix. I hope. Else me and my big mouth :-)
>
> So help me please.
>
> Thanks,
>
> Wim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-20-2008, 10:28 AM
Quetzalcoatl
 
Posts: n/a
Default Re: a how can I do this in Informix question

Thanks a lot.
This is what I was looking for.

W

Art S. Kagel wrote:
> Quetzalcoatl wrote:
>
>> Hello,
>>
>> I have a problem in Informix that I need to solve.
>>
>> I have table
>>
>> Table ABC
>> {
>> Field1 integer,
>> Field2 char(5),
>> Insdate integer
>> };

>
>
>> What I want now is when an insert occurs on this table on the fields
>> (Field1 and Field2) that afterwards the fields Insdate is filled with
>> the date of today but stored as a number in the format YYYYMMDD.

>
>
> How about this as just ONE way to do it:
>
> create procedure create_abc_default_date() returning int
> define result int;
>
> select year(current) * 10000 + month(current) * 100 + day(current)
> into result
> from systables
> where tabid = 1;
>
> return result;
> end procedure;
>
> create trigger abc_ins for insert on abc
> referencing new as rec
> for each row
> update abc set insdate = create_abc_default_date()
> where field1 = rec.field1 and field2 = rec.field2;
>
> Art S. Kagel
>
>> Example:
>>
>> Insert into ABC (Field1, Field2)
>> values (1, "Wim");
>>
>> then should the query
>>
>> Select * from ABC;
>>
>> return:
>>
>> Field1 Field2 Insdate
>> 1 Wim 20051027
>>
>> My collegue found how to do it in Oracle and now I want to prove it
>> also can be done in Informix. I hope. Else me and my big mouth :-)
>>
>> So help me please.
>>
>> Thanks,
>>
>> Wim

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:11 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com