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.
| 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.thanksdeclare @CallLastResult as datetimeset @CallLastResult= 'select max(datetimeofcall) from tablex where columnx=0'datetimeofcall is datetimethis 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 |
 |
|
|
tran008
Starting Member
38 Posts |
Posted - 2004-07-27 : 10:48:41
|
| thank alot RajeevCan you tell me explain why your work? I'm just curious about the statement.thanks |
 |
|
|
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. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-07-27 : 13:15:57
|
| I prefer:SELECT @CallLastResult = MAX(datetimeofcall)FROM TablexWHERE Columnx = 0Tara |
 |
|
|
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 = column5FROM TablexWHERE Columnx = 0- RoLY roLLs |
 |
|
|
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 = column5FROM TablexWHERE Columnx = 0 - RoLY roLLsEDIT: OPPS, sorry. Had some lag, thought it was that i didn't submit before. |
 |
|
|
|
|
|
|
|