View previous topic :: View next topic
|
Author |
Message |
trushant.w
New User
Joined: 22 Sep 2013 Posts: 81 Location: pune india
|
|
|
|
Multiple times i have come across below question in interview.
How to retive current date,time and timestramp from a table and how to recieve them in host varibales
I give them below answers but they wanted to retieve from the table
SELECT CURRENT_TIME FROM SYSIBM.SYSDUMMY1;
SELECT CURRENT_DATE FROM SYSIBM.SYSDUMMY1;
SELECT CURRENT_TIMESTAMP FROM SYSIBM.SYSDUMMY1; |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
but they wanted to retieve from the table |
From which table? I don't understand. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
You could use:
Code: |
select current_timestamp from <table-name> fetch first 1 rows only |
or
Code: |
EXEC SQL
SET :CURRENT-DATE-TIME = CURRENT TIMESTAMP
END-EXEC. |
|
|
Back to top |
|
|
Chetan Kumar
New User
Joined: 03 Dec 2012 Posts: 46 Location: India
|
|
|
|
Hi, you could use select query as below
SELECT CURRENT_TIME INTO :CURRENT-TIME FROM SYSIBM.SYSDUMMY1;
SELECT CURRENT_DATE INTO :CURRENT-DATE FROM SYSIBM.SYSDUMMY1;
SELECT CURRENT_TIMESTAMP INTO :CURRENT-TIMESTAMP FROM
SYSIBM.SYSDUMMY1;
Where Variable preceding colon (:) are called host variables.
Equivalent in COBOL is X(8), X(10) and X(26) respectively. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3049 Location: NYC,USA
|
|
|
|
Chetan, thats a year old post. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
And that is exactly what was posted in the original post. |
|
Back to top |
|
|
|