SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to get MAX value variable
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

snow12
Yak Posting Veteran

74 Posts

Posted - 05/15/2012 :  12:32:37  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
2865 Posts

Posted - 05/15/2012 :  13:16:26  Show Profile  Reply with Quote
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 - 05/15/2012 :  15:44:22  Show Profile  Reply with Quote
Thank you very much!
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2865 Posts

Posted - 05/15/2012 :  17:05:31  Show Profile  Reply with Quote
You're Welcome.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000