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 2005 Forums
 Transact-SQL (2005)
 comparing maxvalue to a variable

Author  Topic 

hanaveenkumar
Starting Member

2 Posts

Posted - 2010-03-01 : 03:30:23
hi,

I want to get max value from a column, and compare that value with a variable say 'tempID' , if both are equal increment 'tempID' by 1..

can any body suggest

Thanks
naveen

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-03-01 : 03:42:34
if((select max(column_name) from table_name)=@tempid)
set @tempid=@tempid+1
else
.....

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-01 : 03:43:29
continue from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=140593


select @tempID = case when max(column) = @tempID then @tempID + 1 else @tempID end
from atable



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -