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)
 How to get MAX value variable

Author  Topic 

snow12
Yak Posting Veteran

74 Posts

Posted - 2012-05-15 : 12:32:37
Hello:

I want to get max order value and store it to the variable, then compare this value.

declare @Largest_Order int
declare @name varchar(50)

select max(order) as @Largest_Order, @name = name from company group by name

if @Largest_order > 20

begin

...


end

However, I got syntax error at select max(order) as @Largest_Order. Where I missed?

Your help is always appreciate.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-05-15 : 13:16:26
select @Largest_Order = max(Largest_Order) from company

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

snow12
Yak Posting Veteran

74 Posts

Posted - 2012-05-15 : 15:44:22
Thank you very much!
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-05-15 : 17:05:31
You're Welcome.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -