On Oct 2, 1:14*pm, Richard <rmcgor...@gmail.comwrote:
That worked. *Thanks. :-)
A couple of follow-up questions:
How would I display the value stored in a variable? *In Sybase I could
"select" it, or "print" it. *The select gives me an error and I don't
see the print option in the "SQL Reference Volume 2" manual. *No other
commands in Volume 2 are popping out as obvious options. *I must be
missing it.
Why do I need to type
* * SELECT current date FROM sysibm.sysdummy1
in my script, instead of
* * SELECT current date
to display the current date, yet in your example you can say
* *SET V_DATENOW = current date
Is it just a difference between the SET versus SELECT command?
Thanks.
Well, not to pick on Sybase, but--while handy--I don't believe a query
like 'SELECT current date' is valid, i.e. well-formed (ANSI), SQL, as
it's missing the FROM clause. Hence the need in DB2 to refer to the
dummy table.
Populating the variable is a different story, as that's in a
procedural context and the current date is coming from a special
register.
In a stored procedure you could also do a SELECT...INTO and populate a
variable using a SELECT, in addition to populating it via SET using a
scalar fullselect. In other words, in DB2, *depending on the setting*
you could do:
DECLARE V_TIMENOW TIMESTAMP;--
SET V_TIMENOW = CURRENT TIMESTAMP;--
--or--
DECLARE V_TIMENOW TIMESTAMP;--
SELECT CURRENT TIMESTAMP INTO V_TIMENOW FROM SYSIBM.SYSDUMMY1;--
Come to think of it, you don't even need SYSIBM.SYSDUMMY1, you also
could do something like:
SELECT CURRENT TIMESTAMP INTO V_TIMENOW FROM TABLE(VALUES(1)) T(C1);--
--or--
DECLARE V_TIMENOW TIMESTAMP;--
SET V_TIMENOW = (SELECT CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY1);--
--Jeff