Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 error on datetime

Author  Topic 

tran008
Starting Member

38 Posts

Posted - 2004-07-27 : 09:58:54
Hi all,
I had the following, and it not co-operating. Anyone can share some light on this would be greatly appreciate.

thanks

declare @CallLastResult as datetime
set @CallLastResult= 'select max(datetimeofcall) from tablex where columnx=0'


datetimeofcall is datetime

this is giving me an error:
Syntax error converting datetime from character string.

rlahoty
Starting Member

11 Posts

Posted - 2004-07-27 : 10:25:11
Remove the quotes from the following statement and :

set @CallLastResult= 'select max(datetimeofcall) from tablex where columnx=0'

Rewrite it as follows:

set @CallLastResult= (select max(datetimeofcall) from tablex where columnx=0)

HTH
-Rajeev Lahoty
Go to Top of Page

tran008
Starting Member

38 Posts

Posted - 2004-07-27 : 10:48:41
thank alot Rajeev

Can you tell me explain why your work? I'm just curious about the statement.

thanks
Go to Top of Page

rlahoty
Starting Member

11 Posts

Posted - 2004-07-27 : 13:08:20
Well, there is nothing fancy about it. You are setting the variable to a string, while the variable declared is of datetime type. And if you need to use SELECT statement for setting a variable, use the syntax as in my statement. Nothing more, nothing less.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-07-27 : 13:15:57
I prefer:

SELECT @CallLastResult = MAX(datetimeofcall)
FROM Tablex
WHERE Columnx = 0

Tara
Go to Top of Page

RoLYroLLs
Constraint Violating Yak Guru

255 Posts

Posted - 2004-07-27 : 15:49:45
I agree with tara, that way you can set more variables like so;

SELECT
@Var1 = column1
,@Var2 = column2
,@Var3 = column3
,@Var4 = column4
,@Var5 = column5
FROM
Tablex
WHERE
Columnx = 0

- RoLY roLLs
Go to Top of Page

RoLYroLLs
Constraint Violating Yak Guru

255 Posts

Posted - 2004-07-27 : 15:50:08
I agree with tara, that way you can set more variables like so;

SELECT
@Var1 = column1
,@Var2 = column2
,@Var3 = column3
,@Var4 = column4
,@Var5 = column5
FROM
Tablex
WHERE
Columnx = 0


- RoLY roLLs

EDIT: OPPS, sorry. Had some lag, thought it was that i didn't submit before.
Go to Top of Page
   

- Advertisement -