Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
try this. It does not use TOP, any aggregate function, ORDER BY.
declare @salary int, @max_salary intdeclare c cursor for select Salary from employeeopen c fetch next from c into @salaryset @max_salary = @salarywhile @@fetch_status = 0begin if @salary > @max_salary select @max_salary = @salary fetch next from c into @salaryend close cdeallocate cselect @max_salary as [max salary]
KH
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2007-03-19 : 09:24:25
Good piece of code!Peter LarssonHelsingborg, Sweden