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.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > set field = current date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-11-03, 14:42
MizzGail2 MizzGail2 is offline
Registered User
 
Join Date: Jul 2003
Posts: 4
Red face set field = current date

I am creating the following trigger. I want to set the last 4 fields to current date and current time. how do i do this?

create trigger ttdpur947
insert on ttdpur045101
referencing new as new
for each row
(insert into ttdpur947101 values
(new.t_orno,
new.t_pono,
new.t_srnb,
new.t_reno,
new.t_dqua,
new.t_quap,
new.t_quad,
t_crdt,
t_crtm,
t_chdt,
t_chtm ))
Reply With Quote
  #2 (permalink)  
Old 07-11-03, 14:52
aruneeshsalhotr aruneeshsalhotr is offline
Registered User
 
Join Date: Jul 2003
Location: US
Posts: 314
Current Date and Current Time

I am not sure about the procedures and functions, but I will try to answer your query to the best of my knowledge.
use to_char(SYSDATE,'YYYY/MM/DD') and to_char(SYSDATE,'HH:MIS')
as the parameters.

Let me know if it helps.
Thanx and Regards
Aruneesh
Reply With Quote
  #3 (permalink)  
Old 07-11-03, 14:54
MizzGail2 MizzGail2 is offline
Registered User
 
Join Date: Jul 2003
Posts: 4
Question

Not sure what you mean.........
Reply With Quote
  #4 (permalink)  
Old 07-11-03, 14:56
aruneeshsalhotr aruneeshsalhotr is offline
Registered User
 
Join Date: Jul 2003
Location: US
Posts: 314
Arrow Corrections

Hi
If you want to get the current date and time, the values i mentioned earlier could be used.

Like you have the following fields (t_crdt, t_crtm, t_chdt and t_chtm).
Just use the my values in place of the variables.

If that doesnt explain what I am talking about, could be a more specific as to what u r trying to accomplish.

Thanx and Regards
Aruneesh
Reply With Quote
  #5 (permalink)  
Old 07-11-03, 15:00
MizzGail2 MizzGail2 is offline
Registered User
 
Join Date: Jul 2003
Posts: 4
It gives me a syntax error

new.t_quad,
to_char(SYSDATE,'YYYY/MM/DD')
t_crtm,
t_chdt,
t_chtm ))

201: A syntax error has occurred.


I have a table already defined with these fields in it to be used elsewhere. I want them to default to the creation date and time that the record is inserted into my table.
Reply With Quote
  #6 (permalink)  
Old 07-11-03, 15:07
aruneeshsalhotr aruneeshsalhotr is offline
Registered User
 
Join Date: Jul 2003
Location: US
Posts: 314
More questions

I have not work on procedures, but I would try my best to get the thing resolved for you.
First could you let me know the datatype for the following fields. Are they all DATE fields or varchar2.

t_crdt, t_crtm, t_chdt, t_chtm

If they are varchar2, then the solution i provided would work fine, else just use SYSDATE, at every step.
That would surely work for you.

Thanx and Regards
Aruneesh
Reply With Quote
  #7 (permalink)  
Old 07-11-03, 15:33
MizzGail2 MizzGail2 is offline
Registered User
 
Join Date: Jul 2003
Posts: 4
thank you for your suggestions, I have written a lot of queries but we don't normally write triggers or updates.

they are defined as data and integer.

I just found the function TODAY that works for the date.

still looking for something to handle the time.

CURRENT gives date and time....
Reply With Quote
  #8 (permalink)  
Old 07-11-03, 15:35
aruneeshsalhotr aruneeshsalhotr is offline
Registered User
 
Join Date: Jul 2003
Location: US
Posts: 314
CURRENT

Hi
With my experience with queries, dont have stuff like to_char and to_date in case of triggers. I am pretty sure that there would be stuff like that to filter out the required information.

Do let me know if it gets you anywhere.
Thanx and Regards
Aruneesh
Reply With Quote
  #9 (permalink)  
Old 07-11-03, 19:01
Seppuku Seppuku is offline
Useless...
 
Join Date: Jul 2003
Location: SoCal
Posts: 721
Try GETDATE()... It'll return the current date and time... now, this works in MS SQL Server... not sure what platform you're on though

SELECT GETDATE() AS datetime
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On