|
From: icanhelp33 on 16 Jul 2008 18:07 declare @max int select count(lastname) from customers where payment>200 I would like to store the results on the query in @max. How can I do that
From: Vern Rabe on 16 Jul 2008 18:20 SELECT @max = COUNT(lastname) FROM customers WHERE payment > 200; or SET @max = (SELECT COUNT(lastname) FROM customers WHERE payment > 200); HTH Vern Rabe "icanhelp33(a)gmail.com" wrote: > declare @max int > > select count(lastname) from customers where payment>200 > > I would like to store the results on the query in @max. How can I do > that >
From: Erland Sommarskog on 16 Jul 2008 18:49 (icanhelp33(a)gmail.com) writes: > declare @max int > > select count(lastname) from customers where payment>200 > > I would like to store the results on the query in @max. How can I do > that select @max = count(lastname) from customers where payment>200 -- Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
From: icanhelp33 on 16 Jul 2008 19:29 select @max=count(distinct Event) FROM OrderLineItems GROUP BY OrderId How can I get the max from count(distinct Event) FROM OrderLineItems GROUP BY OrderId then store it in @max
From: Plamen Ratchev on 16 Jul 2008 22:03 Here is one way: SELECT @max = MAX(cnt) FROM (SELECT COUNT(DISTINCT Event) FROM OrderLineItems GROUP BY OrderId) AS T(cnt); HTH, Plamen Ratchev http://www.SQLStudio.com
|
Next
|
Last
Pages: 1 2 Prev: Getting the opposite of a join table Next: Retive username / machine name |