From: icanhelp33 on
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
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
(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
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
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