Discussion:
print datetime variable sybase
(too old to reply)
d***@gmail.com
2005-11-03 20:05:05 UTC
Permalink
Hi,

I have a datetime variable that I wish to print out everytime my stored
proc runs. How do I do that? I am using Sybase Adaptive Server
Module.

I tried something like,

print "date is...%1",@date1 and it said taht the print function only
accepts char or varchars as arguments.

Any ideas?

Thanks,
b***@sybase.com
2005-11-03 20:35:00 UTC
Permalink
declare @foo varchar(255)
select @foo = convert(varchar(255), @date1)

print "date is %1", @foo
d***@gmail.com
2005-11-03 20:59:30 UTC
Permalink
do i need to convert it to varchar each time i want to print it? no
direct way of printing a date in sybase?
w***@csc.com
2005-11-03 21:21:06 UTC
Permalink
It depends on why you are using the print command.

If all you need is a line with the date, just select the variable or
the getdate() function.

1> declare @date1 datetime
2> select @date1 = getdate()
3> select 'date is ', @date1
4> go
(1 row affected)

-------- --------------------------
date is Nov 3 2005 4:20PM

(1 row affected)
1> select 'date is', getdate()
2> go

------- --------------------------
date is Nov 3 2005 4:20PM

(1 row affected)
d***@gmail.com
2005-11-03 22:11:50 UTC
Permalink
Well, a few things.

1) helpful during debugging to print out various variables (ints,
floats, datetime).
2) i get loading data as a parameter to a stored proc, and sometimes
would like to print it to see what it is...
b***@sybase.com
2005-11-03 22:46:18 UTC
Permalink
Is there a reason you don't just use


"select getdate()"
b***@sybase.com
2005-11-03 22:46:25 UTC
Permalink
Is there a reason you don't just use


"select getdate()"
w***@csc.com
2005-11-04 14:27:07 UTC
Permalink
Which ASE version are you using. My tests show automatic conversion to
character then a successfull print.
Versions tested 11.0.3.3
, 11.9.2.4
, 12.0.0.6
, 12.5.0.3
, 12.5.2

1> Set nocount on
2> select @@version
3> declare @a varchar(10)
4> declare @b int
5> declare @c float
6> declare @d datetime
7> declare @e numeric(10,2)
8> select @a = 'abcde'
9> select @b = 100
10> select @c = 100.50
11> select @d = '10/31/2004'
12> select @e = 100.50
13> print "variable test char %1!", @a
14> print "variable test int %1!", @b
15> print "variable test float %1!", @c
16> print "variable test datetime %1!", @d
17> print "variable test numeric %1!", @e
18> print "all variables test %1!, %2!, %3!, %4!, %5!", @a, @b, @c, @d,
@e
19>
20> go








---------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------


Adaptive Server Enterprise/11.9.2.4/1177/P/SWR 9580 ESD
4/HP9000-735/HP-UX 10.2/FBO/Thu Apr 5 17:48:52 2001



variable test char abcde
variable test int 100
variable test float 100.5
variable test datetime Oct 31 2004 12:00AM
variable test numeric 100.50
all variables test abcde, 100, 100.5, Oct 31 2004 12:00AM, 100.50
d***@gmail.com
2005-11-03 20:59:24 UTC
Permalink
do i need to convert it to varchar each time i want to print it? no
direct way of printing a date in sybase?
Loading...