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 |
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-01-26 : 08:10:02
|
| Objective:I am attempting to select all records from a table f0902_aot with a jobkey greater than the maximum jobkey less 5.I am trying:DECLARE @maxjobkey varchar(6);set @maxjobkey = 'select max (jobkey)from f0902_aot'select * from F0902_AOT where Jobkey > cast(@maxjobkey - 5) And I receive the following error message:Msg 1035, Level 15, State 10, Line 3Incorrect syntax near 'cast', expected 'AS'.Thank you |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-01-26 : 08:12:48
|
| DECLARE @maxjobkey int;set @maxjobkey = select max (jobkey)from f0902_aot;select * from F0902_AOT where Jobkey > (@maxjobkey - 5); |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-01-26 : 08:29:03
|
| Now I receive the following:Msg 156, Level 15, State 1, Line 2Incorrect syntax near the keyword 'select'. |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-01-26 : 09:28:12
|
| Actually, have worked this out now.Thank you for your help |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-01-27 : 05:26:18
|
| Did you use this?DECLARE @maxjobkey int;set @maxjobkey = (select max (jobkey)from f0902_aot;select * from F0902_AOT where Jobkey > (@maxjobkey - 5));MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|