Home All Groups Group Topic Archive Search About

dont show select results

Author
1 Sep 2005 2:45 PM
Carlo
hi
is it possible in a query dont show the result rows??
i wanna write

select *
from table

set @num=@@rowcount

and i dont wanna see all the rows affected
thanks
Carlo

Author
1 Sep 2005 2:53 PM
Aaron Bertrand [SQL Server MVP]
How about

SELECT @num = COUNT(*) FROM table


Show quote
"Carlo" <carletto.m@NOSPAMgmail.com> wrote in message
news:%23kaDMPwrFHA.1788@tk2msftngp13.phx.gbl...
> hi
> is it possible in a query dont show the result rows??
> i wanna write
>
> select *
> from table
>
> set @num=@@rowcount
>
> and i dont wanna see all the rows affected
> thanks
> Carlo
>
Author
1 Sep 2005 3:07 PM
Carlo
thanks

another stupid question:
can i dont write the message like :
(7 row(s) affected)

?????
thanks
carlo


Show quote
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> ha scritto nel
messaggio news:ugcV$SwrFHA.1204@TK2MSFTNGP15.phx.gbl...
> How about
>
> SELECT @num = COUNT(*) FROM table
>
>
> "Carlo" <carletto.m@NOSPAMgmail.com> wrote in message
> news:%23kaDMPwrFHA.1788@tk2msftngp13.phx.gbl...
>> hi
>> is it possible in a query dont show the result rows??
>> i wanna write
>>
>> select *
>> from table
>>
>> set @num=@@rowcount
>>
>> and i dont wanna see all the rows affected
>> thanks
>> Carlo
>>
>
>
Author
1 Sep 2005 3:10 PM
Aaron Bertrand [SQL Server MVP]
SET NOCOUNT ON
Author
1 Sep 2005 2:54 PM
David Portas
SET @num =
(SELECT COUNT(*)
  FROM table)

Note that @@ROWCOUNT will now be 1regardless of the value returned in
@num.

--
David Portas
SQL Server MVP
--
Author
1 Sep 2005 3:00 PM
Alejandro Mesa
Carlo,

What for is @num?. You can do the following:

select @num = count(*) from t1 where ...
....

or

if exists(select * from t1 where ...)
   ...


AMB


Show quote
"Carlo" wrote:

> hi
> is it possible in a query dont show the result rows??
> i wanna write
>
> select *
> from table
>
> set @num=@@rowcount
>
> and i dont wanna see all the rows affected
> thanks
> Carlo
>
>
>
Author
1 Sep 2005 3:07 PM
David Gugick
Carlo wrote:
> hi
> is it possible in a query dont show the result rows??
> i wanna write
>
> select *
> from table
>
> set @num=@@rowcount
>
> and i dont wanna see all the rows affected
> thanks
> Carlo

Row Affected shows up when you have not set SET NOCOUNT ON. You've
already received the answer if what you wanted was to not see the rows
themselves, but when reading your post, it's not clear what you want.

If you want to see all the rows, then define the select statement with
only the columns you need. Assuming you're fetching them on the client,
you can count the rows there.

If all you need is the rowcount for the select statement, then read the
other posts about assigning the count to a local variable.

You should always have SET NOCOUNT ON as the first statement of each
stored procedure and as the first SQL call from an application that uses
embedded SQL. That will suppress the "x Row(s) Affected" message.

--
David Gugick
Quest Software
www.imceda.com
www.quest.com

AddThis Social Bookmark Button