Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column Default Date

Status
Not open for further replies.

skydive

Programmer
May 30, 2001
16
IE
Hi All,

I am trying to write a database creation script and on one table I need to assign a default date to a column of data type "DATETIME YEAR TO MINUTE". I wish to assign the current date.
Any help would be great!

Blue Skies
Skydive.
 
Skydive:

I don't know how your 'creation script' populates the tables, but use the current keyword. The stored procedure below illustrates the concept.

An as we use to say in the airborne: Keep your feet and knees together!

Ed
Schaefer

-- This function returns a datetime year to minute
CREATE PROCEDURE ret_dt()
RETURNING DATETIME YEAR TO MINUTE;
DEFINE dt_ret DATETIME YEAR TO MINUTE;

create temp table b (
dts datetime year to minute
) with no log;

insert into b values (CURRENT);
select dts into dt_ret from b;

drop table b;

RETURN dt_ret;
END PROCEDURE;
 
Hi Ed,

Thanks for the reply,
I'll explain futher what I am trying to do:
I have a SQL script which creates the database and tables (I'm importing data afterwards using the MS-DTC from another DBMS)
Below you'll find the troublesome table, I have made the problem line in RED

create table report_result_head (
report_result_id serial(10001) not null,
report_name varchar(50),
served_flag char(1) default "n"
check (served_flag is null or ( served_flag in ("y","n"))),

create_date datetime year to minute default CURRENT,

primary key (report_result_id)
constraint pk_report_result_h
);

Thanks & Blue One's
Colin
 
I believe you're going to have to write a trigger to make this happen. I haven't written a trigger in several years, so I'd have to pull out the manual.

It you read the thread HELP WITH TRIGGERS right after this thread, it should give you some idea how to proceed.

regards,

Ed
 
Hi Ed,
Yeah I think you may be right, I wanted to stay away from using a trigger if possible but I can't see any other way of doing it.

Thanks Ed for your help.

Regards
Colin

 
Colin:

Looks like I didn't help you all that much, but you're welcome.

Thanks,

Ed
 
You need to use a TODAY function.
Use it on place of CURRENT function.

Rosti
 
Dear Friend,

Specify the exact date time qualifier at your default current. Replace the redlines with the following:


create_date datetime year to minute default current year to
minute,

Try this out.

G.R.P.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top