How Top And Set Rowcount Actually Works

Jan 15, 2008

I'm coming from Oracle world and my knowledge about SQL Server is quite limited so I apriori apologize for probably stupid questions

DB version is SQL Server 2005.
The business scenario is - there is search form with many criteria. User may enter very unrestrictive criteria matching probably millions of rows. To prevent that we'd like to show him no more than N rows (N ~200). Any rows matching criteria are good enough, however these FOUND rows we'd like to sort. I do not want to find all potentially X million rows, then sort them and only then show forst N rows.
So in Oracle I know how to do that. I just find N rows in subquery, and then in outer query sort them. So I avoid to find all rows and then sorting millions of rows.
Here is an example:



Code Block
SQL> create table t (id number, data varchar2
Table created.
SQL> insert into t values (1, 'aaa');
1 row created.
SQL> insert into t values (2, 'bbb');
1 row created.
SQL> insert into t values (3, 'ccc');
1 row created.
SQL> select * from (
2 select * from t where rownum <=2)
3 ;
ID DATA
---------- --------------------
1 aaa
2 bbb
SQL> ed
Wrote file afiedt.buf
1 select * from (
2 select * from t where rownum <=2)
3* order by data desc
SQL> /
ID DATA
---------- --------------------
2 bbb
1 aaa





However how can I avoid sort of potential big result in SQL Server? I've searched google but unfortunately found nothing.
I've tried to use both TOP and SET rowcount without success i.e. from these examples I assume that DB will find ALL rows matching where clause then sort them keeping only first N. It seems that order by clause in outer query is pushed into inner query both for top and set rowcount.




Code Block
create table t (id integer, data varchar(20));
insert into t values (1, 'aaa');
insert into t values (2, 'bbb');
insert into t values (3, 'ccc');

select * from (
select top 2 * from t) as q


1 aaa
2 bbb


select * from (
select top 2 * from t) as q
order by data desc

3 ccc
2 bbb


set rowcount 2
select * from (
select * from t) as q


1 aaa
2 bbb


set rowcount 2
select * from (
select * from t) as q
order by data desc

3 ccc
2 bbb







And I'd like to avoid sort because of two reasons:
1) I predict that generally finding all rows will be much more costly than finding just any no more than N
2) Sorting all found rows also probably will be slower than just N (however DB has to find only first N rows, so not ALL rows should be sorted/kept sorted)


Are my concerns reasonable? If yes what can I do to just find N rows and sort only these?

TIA, Gints

View 12 Replies


ADVERTISEMENT

Rowcount - Returning Rowcount From SSIS To A Vb.net App Executing The Dtsx Package

Jul 7, 2006

I have a vb.net application that executes a simple flat file to sql table dtsx package. I want to capture the rowcount to display back to the user to verify the number of rows that were inserted or updated to the table. I have a Row Count component placed between the flat file source(without errors) and the destination component. I have assigned a variable named RecordCount to the Row Count component. So far so good I hope : )

Now, I also use a variable to "feed" the package the flat file source. This works fine, but I cannot figure out how to retrieve the row count information and how to assign that to the variable RecordCount.

Also, if anyone has any insight on the way to work with the OnProgress method in SSIS I would appreciate that as well. In SQL 2000 using DTS I create a "PackageEventsSink" that I had found online, and it worked great for monitoring the progress of the DTS. Can't seem to figure out how to get it to work in SSIS.

Thanx,

Mike

View 11 Replies View Related

SQL LOJ Rowcount &&> SSIS MergeJoin Rowcount. Why?

Jul 25, 2007

In sql I perform the following
SELECT * FROM
xlsdci x LEFT OUTER JOIN fffenics f ON f.[derived deal code] = x.[manual dcd id]

which gives me a row count of 2709 rows


In SSIS I have a merge join component (left outer)
left input = xlsdci with a sort order of 1 ASC on [manual dcd id] (OLE DB source component)
right input = fffenics with a sort order of 1 ASC on [derived deal code] (OLE DB source component)

which when run in the IDE gives me a rowcount of only 2594 rows

Why is this so?

Also if I change the join to INNER in the merge join, the number of rows drops dramatically to only 802.
Fair enough, I hear you cry, maybe there are IDs in the 'xlsdci' table that are not in the 'fffenics' table. Ok. But the following SQL reveals that there are only 14 rows(IDs) in 'xlsdci' that are not in 'fffenics'

SELECT * FROM xlsdci
WHERE [manual dcd id] NOT IN (SELECT [derived deal code] FROM dbo.fffenics)

What is going on here?

View 5 Replies View Related

SQL SERVER ACCESS DENIED!! BUT Everything Works On MSDE And Works SHOWING RECORDS ON SQL SERVER!! PLEASE HELP

Jul 26, 2004

I've got a popular problem so i get a message that server acces denied! ..

But that what is different in my error.... When i use same setting same database and connection string (on MSDE server) there is no problem...

On SQL server i have got windwos authentication but i added all accounts as ASPNET and SA.... and when i try to connect by

RETTO - name of my server

server=RETTO;uid=sa;pwd=password;database=db1;
or by
Integrated Security=SSPIserver=RETTO;uid=RETTOASPNET;database=db1;

I CAN BROWSE RECORDS THERE ARE NO PROBLEMS WITH CONNECTION!!! but when i try to update or iinsert or delete something in database there becomame this error that access denied or server does not exist!!!


PLEASE HELP I'm FIGHTING WITH THAT FOR OVER 5 DAYS!!!

I MADE FOR MY ACCOUNTS (SA, ASPNET) ALL THINGS ALLOWED AS EXECUTING stored procedures.. OR ACCESING datatables with insert delete and update query WHERE IS THE PROBLEM!!!??

View 3 Replies View Related

Telnet Connection Works, Sql Cmd Connection Works, SQL Server Managment Studio 2005 Does Not

Jun 20, 2007

I'm having a strange problem with this but I know (and admit) that the problem is on my PC and nowhere else. My firewall was causing a problem because I was unable to PING the database server, switching this off gets a successful PING immediately. The most useful utility to date is running netstat -an in the command window. This illustrates all the connections that are live and ports that are being listed to. I can establish a connection both by running



telnet sql5.hostinguk.net 1433 and

sqlcmd -S sql5.hostinguk.net -U username -P password



See below:



Active Connections

Proto Local Address Foreign Address State

TCP 0.0.0.0:25 0.0.0.0:0 LISTENING

TCP 0.0.0.0:80 0.0.0.0:0 LISTENING

TCP 0.0.0.0:135 0.0.0.0:0 LISTENING

TCP 0.0.0.0:443 0.0.0.0:0 LISTENING

TCP 0.0.0.0:445 0.0.0.0:0 LISTENING

TCP 0.0.0.0:1026 0.0.0.0:0 LISTENING

TCP 0.0.0.0:1433 0.0.0.0:0 LISTENING

TCP 81.105.102.47:1134 217.194.210.169:1433 ESTABLISHED

TCP 81.105.102.47:1135 217.194.210.169:1433 ESTABLISHED

TCP 127.0.0.1:1031 0.0.0.0:0 LISTENING

TCP 127.0.0.1:5354 0.0.0.0:0 LISTENING

TCP 127.0.0.1:51114 0.0.0.0:0 LISTENING

TCP 127.0.0.1:51201 0.0.0.0:0 LISTENING

TCP 127.0.0.1:51202 0.0.0.0:0 LISTENING

TCP 127.0.0.1:51203 0.0.0.0:0 LISTENING

TCP 127.0.0.1:51204 0.0.0.0:0 LISTENING

TCP 127.0.0.1:51206 0.0.0.0:0 LISTENING

UDP 0.0.0.0:445 *:*

UDP 0.0.0.0:500 *:*

UDP 0.0.0.0:1025 *:*

UDP 0.0.0.0:1030 *:*

UDP 0.0.0.0:3456 *:*

UDP 0.0.0.0:4500 *:*

UDP 81.105.102.47:123 *:*

UDP 81.105.102.47:1900 *:*

UDP 81.105.102.47:5353 *:*

UDP 127.0.0.1:123 *:*

UDP 127.0.0.1:1086 *:*

UDP 127.0.0.1:1900 *:*

Both these utilities show as establishing a connection in netstat so I am able to connect the database server every time, this worked throughout yesterday and has continued this morning.

The problem is when I attempt to use SQL Server Management Studio. When I attempt to connect to tcp:sql5.hostinguk.net, 1433 nothing shows in netstat at all. There is an option to encrypt the connection in the connection properties tab in management studio, when I enable this I do get an entry in netstat -an, see below:



TCP 81.105.102.47:1138 217.194.210.169:1433 TIME_WAIT

TCP 81.105.102.47:1139 217.194.210.169:1433 TIME_WAIT

TCP 81.105.102.47:1140 217.194.210.169:1433 TIME_WAIT



Amost as if it's trying the different ports but you get this time_wait thing. The error message is more meaningful and hopefull because I get:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.) (.Net SqlClient Data Provider)

I would expect this as the DNS has not been advised to encrypt the conection.

This is much better than the : Login failed for user 'COX10289'. (.Net SqlClient Data Provider) that I get, irrespective of whether I enter a password or not.


This is on a XP machine trying to connect to the remote webhosting company via the internet.

I can ping the server

I have enabled shared memory and tcp/ip in protocols, named pipes and via are disabled

I do not have any aliases set up

No I do not force encryption

I wonder if you have any further suggestions to this problem?

View 7 Replies View Related

I Don't Understand How This Works, However It Works (sometimes)

Sep 26, 2006

I use the code below for updating data from a AS400 Liked server. I dont understend how the WHERE NOT EXISTS( sections work however usualy they do, in this case it does not andt I can't seem to find out why.

Does anyone see the error?

Thanks

--=========================================
--Create a local temporary table that hold
--all the data from the source table
--=========================================

SELECT * INTO #TEMP FROM dbo.LINK_LTTSTOC

--=========================================
--Remove table entries that are no longer
--needed or that have to be updated
--=========================================

DELETE FROM LTTSTOCK

WHERE NOT EXISTS( SELECT * FROM #TEMP

WHERE LTTSTOCK.WarehouseNo = LTWHLO

AND LTTSTOCK.Location = LTWHSL

AND LTTSTOCK.ItemNo = LTITNO

AND LTTSTOCK.NumberAvail = LTAVAL

)

--=========================================

--Insert data that is missing or that

--needed to be updated and was previously

--deleted

--=========================================

INSERT INTO dbo.LTTSTOCK(WarehouseNo,Location,ItemNo,NumberAvail,rowguid)

SELECT DISTINCT LTWHLO,LTWHSL,LTITNO,LTAVAL, NEWID()

FROM #TEMP

WHERE NOT EXISTS( SELECT * FROM LTTSTOCK

WHERE WarehouseNo = LTWHLO

AND Location = LTWHSL

AND ItemNo = LTITNO

AND NumberAvail = LTAVAL

)

--========================================

--Remove local temporary table.

--========================================

DROP TABLE #TEMP

View 2 Replies View Related

Rowcount

Feb 14, 2002

Can anybody help ?

I need to get a limited set of records from sorted record set. For example, I have a table called Contacts which contains about 2000 records and I need to show records from 11 to 20 in the sorted order.

In Oracle I could use this query.

SELECT name FROM
(SELECT name, ROWNUM rnum from Contacts order by Name)
WHERE rnum between 11 and 20

Is anything equivalent available in SQL Server ? My need is to show
records page by page ( as in google/yahoo search ) in my asp page.

Thanks
Subhash

View 1 Replies View Related

SET ROWCOUNT

Nov 13, 2000

Does anybody know how to get at the value set by a SET ROWCOUNT statement from within a Stored Procedure. e.g. If I executed the following:-

SET ROWCOUNT 50
EXEC Proc1

How could Proc1 find out that the User had done a SET ROWCOUNT 50.

Any ideas would be appreciated

View 1 Replies View Related

@@Rowcount

Feb 8, 2001

Can @@rowcount be used with a regular select statement?

Thanks,
Ninel

View 2 Replies View Related

Rowcount

Aug 15, 2002

Can someone send me the script that counts the rows of the table within
a database?

Thanks,
Dianne

View 3 Replies View Related

RowCount VS TOP

Jul 25, 2005

Is Set RowCount @RowCountMore efficient than simply using TOP?Thanks for any input.

View 5 Replies View Related

Rowcount Help

May 20, 2006

i'm trying to get total rows found by query that uses top clause...for example:select top 10 myTable.* from myTable where myTable.number > 200let's say there are 13 rows matching that condition, and by using@@rowcount my result would be: 10.is there any way to get total row count, without affecting the TOPclause??? i believe that the mysql equivalent would beSQL_CALC_FOUND_ROWS().tnx...

View 1 Replies View Related

Getting The Value Of SET ROWCOUNT

Sep 7, 2006

I'm writing an INSERT, UPDATE and DELETE trigger on table A that needs to insert rows into a table B.

When a user issues a "SET ROWCOUNT" command to limit the number of rows, then does an insert, update or delete, the trigger is being limited to that number.

It is important that the trigger NOT be limited to ANY specific number of records, but it is undesireable for me to just wipe out the current "SET ROWCOUNT" setting for the user without their knowledge.

How do I get and preserve the current "SET ROWCOUNT" value from within my trigger, so I can cancel the limitation and then re-implement the setting once my work is done? I cannot find any documentation specifying where the ROWCOUNT value is set (I initially thought maybe the SYSPROCESSES table, but that doesn't seem to be it).

Example:

set rowcount 1

update TABLEA set val=val+1

<the TABLEA trigger fires, trying to insert multiple rows into TABLEB but is limited to a single row>



Ideas?

View 1 Replies View Related

Rowcount

Sep 5, 2007

Hi,

I am using ssis to import .csv files into sql server tables.
How do I get the count of the records imported?
Thanks

View 3 Replies View Related

RowCount

Jun 26, 2006

Hi,

want to get the number of rows i'm retrieving from a source. This count should be written as " No: of roes retrieved" + varname

I have used OleDbSource, RowCount,Script [ To write in a file ]. Rows is the package level variable name used in rowcount. when i do this way it always writes as 0 in the file.

[code in Script]

Dim sw As New StreamWriter("D:Vijay1.txt")

s = Variables.Rows

sw.WriteLine(s.ToString)

sw.close

[/Code]

Can anyone help on this

View 12 Replies View Related

Getting A Rowcount

Dec 17, 2007



I have a data flow task which contains an XML Source, The XML Source puts data into two OLEDB Destination tasks. What i need to do is check that the number of rows inserted in to the two data bases . Can anyone suggest the easiest way as i need to check before i can commit the transactions. Any help would be most appriciated

Thanks

View 1 Replies View Related

Rowcount And SQLDataReader

Aug 29, 2006

Hi, from what I can find, there isn't a way to get the number of rows returned from a SQLDataReader command. Is this correct? If so, is there a way around this? My SQLDataReader command is as follows:Dim commandInd As New System.Data.OleDb.OleDbDataAdapter(strQueryCombined, connInd)Dim commandSQL As New SqlCommand("GetAssetList2", connStringSQL)Dim resultDS As New Data.DataSet()'// Fill the dataset with valuescommandInd.Fill(resultDS)'// Get the XML values of the dataset to send to SQL server and run a new queryDim strXML As String = resultDS.GetXml()Dim xmlFileList As SqlParameterDim strContainsClause As SqlParameter'// Create and execute the search against SQL ServerconnStringSQL.Open()commandSQL.CommandType = Data.CommandType.StoredProcedurecommandSQL.Parameters.Add("@xmlFileList", Data.SqlDbType.VarChar, 1000).Value = strXMLcommandSQL.Parameters.Add("@strContainsClause", Data.SqlDbType.VarChar, 1000).Value = strContainsConstructDim sqlReaderSource As SqlDataReader = commandSQL.ExecuteReader()results.DataSource = sqlReaderSourceresults.DataBind()connStringSQL.Close()And the stored procedure is such:DROP PROC dbo.GetAssetList2;GOCREATE PROC dbo.GetAssetList2(@xmlFileList varchar(1000),@strContainsClause varchar(1000))ASBEGINSET NOCOUNT ONDECLARE @intDocHandle intEXEC sp_xml_preparedocument @intDocHandle OUTPUT, @xmlFileListSELECT DISTINCTAssetsMaster.AssetMasterUID,SupportedFiles.AssetPath,FROM AssetsMaster, OPENXML (@intDocHandle, '/NewDataSet/Table',2) WITH (FILENAME varchar(256)) AS x,SupportedFilesWHEREAssetsMaster.AssetFileName = x.FILENAMEAND AssetsMaster.Extension = SupportedFiles.Extension UNIONSELECT DISTINCTAssetsMaster.AssetMasterUID,SupportedFiles.AssetPath,FROM AssetsMaster, OPENXML (@intDocHandle, '/NewDataSet/Table',2) WITH (FILENAME varchar(256)) AS x,SupportedFilesWHEREAssetsMaster.AssetFileName <> x.FILENAMEAND CONTAINS ((Description, Keywords), @strContainsClause)AND AssetsMaster.Extension = SupportedFiles.ExtensionORDER BY AssetsMaster.Downloads DESCEXEC sp_xml_removedocument @intDocHandle ENDGOHow can I access the number of rows returned by this stored procedure?Thanks,James

View 3 Replies View Related

How To Get Rowcount From Table

Aug 16, 2007

Hi guys, can anybody help to solve this problem.
set @count=0Insert into User_t (userid, counter) select userid, count+1 from resultset is not working
0/p: bhasker 1      bhanu   1     kishore 1
but o/p must be  bhasker 1 bhanu   2 kishore 3

View 5 Replies View Related

Top N[Percent] VS Set ROWCOUNT N

Nov 17, 2007

Hi all
whether using TOP clause in SELECT statement or [SET ROWCOUNT n] before SELECT statement, I want to know how SqlServer Behave?
whether Fetching data and then choosing n record of them or as soon as fetching n records , Sql Server Stops retrieving the rest of the data?
Thanks in advance.
Regards.

View 1 Replies View Related

If @@Rowcount = .... Problem

Jun 16, 2004

Hello again everyone.....

Ok here's my problem.... This is definetly the strangest problem Ive had yet in my coding career..... anyways here it is:

I have a stored procedure which keeps a total number of hits for specific pages:


Procedure CMRC_Hits_Pages_Temp_Update
@Transaction nvarchar(20),
@Hits int = NULL,
@Page nvarchar(50) = NULL
AS

IF @Transaction = 'Delete'
BEGIN

DELETE FROM CMRC_Hits_Pages_Temp

END

IF @Transaction = 'Add'
BEGIN

CREATE TABLE #TempTableUpdate
(
Hits int
)
INSERT INTO #TempTableUpdate
(
Hits
)
SELECT
Hits
FROM
CMRC_Hits_Pages_Details
WHERE
Page = @Page
SELECT
Hits
FROM
#TempTableUpdate



IF @@Rowcount > 0
BEGIN

UPDATE CMRC_Hits_Pages_Temp
SET
Hits = Hits + @Hits
WHERE
Page = @Page

END

IF @@Rowcount < 1
BEGIN

INSERT INTO CMRC_Hits_Pages_Temp
(
Hits,
Page
)
VALUES
(
@Hits,
@Page
)

END

END


I've written it so if there hasn't been an entry for @Page, make a new one..... And if there is an entry allready for @Page, add @Hits to Hits.

Here's the strange part. When I run it in Query Analyzer (so I know there isn't a problem with my pages code), it works fine when I send @Page a value of 'Default' (As in my default page). But when I put any other value (ei. 'ProductsList', ProductDetails', 'test', 'Defauls') it doesn't work. It creates a new record even if there was a record for that page allready. I've tried erasing everything from the table over and over to give it a fresh start and it still only works for 'Default.'

I've tried every length of string possible thinking it may be the length, same problem.

It makes no sense to me why specific letters could make any difference in what this procedure does. A string is a string, right? Why should one string be more recognizable than another? Again, the most confusing thing I've enountered yet in my coding career.

I seem to always run into problems and think "this makes no sense" and then come to figure "Ohhh.... thats whats wrong..." But this problem here is definetely the cream.... It makes NO sense.....

Thank you to whomever can solve this mystery..... (If it is much of one....)

Just incase the Table info is important:

I have two Columns: Hits, int (4) & Page, nvarchar (50)


-Alec

View 2 Replies View Related

Problems With @@ROWCOUNT

Nov 1, 2005

Hi,I am just starting sql and have a stored proc which does a simple select and should return 2 when no rows match the selection criteria . The problem is that it always returns 2, even where there are rows which match the selection criteria and when there are no rows.CREATE PROCEDURE dbo.SelectSomething                                @a   INT,                            @b   INTAS  SET NOCOUNT ON            SELECT a, b, c, d FROM dbo.SomeTable WITH (READUNCOMMITTED)                                         WHERE  a = @a AND b = @b         IF @@ERROR<>0                     RETURN 1         IF @@ROWCOUNT=0                      RETURN 2  -- Always Returns 2RETURN 0GOThanks for any help.

View 2 Replies View Related

@@ROWCOUNT AND TRANSACTION

Jan 11, 2006

I was testing some checking techniques to add to my SPs while retreiving data or inserting a series of reocords to a series of tables.
Check this testing small piece of code:begin transaction t1
select * from roles where rolename = 'student'

if @@rowcount = 0
goto cleanup

select * from users

if @@rowcount = 0
goto cleanup

commit transaction t1

goto endup
cleanup:
rollback transaction t1
SET ROWCOUNT 0

endup:
print @@rowcount

On one of the testing cases: I made the first query return 1 record and the second returned 5 records, so we ended up at the label "endup", I printed out the RowCount it was 0, does the commit transaction reset that variable?
In addition, are there smart and effective techniques to check against validity of the query statements inside the SP, for example, I can use @@ERROR and @@ROWCOUNT in a transaction based SP to know if I proceed with sub queries, are there more stuff like that?
 
Regards

View 5 Replies View Related

Rowcount Of Views

Mar 26, 2001

I want to create a stored procedure where I pass the name of a view, the number of rows in the view is determined. If the number of rows is zero, I want the sp to fail with an error code that would bring the DTS that executed the sp down. Here is the sp so far. Note that I am EXECuting a sql string because the FROM clause cannot accept a passed variable. Problem is I need the value of my counter variable(@resultcount) to be available after the EXEC statement. Any ideas on how to do this?


CREATE PROCEDURE CheckForEmpty
@tablename varchar(50)
AS
declare @resultcount integer
declare @sSql varchar(255)
--SP to check for rowcount in passed table name. Useful in DTS steps to stop load process if no rows in sending table.

set @sSql = 'set @resultcount = (select count(*) from ' + @tablename + ')'

exec (@sSql)

if @resultcount = 0 RETURN(-99) else return(0)

View 1 Replies View Related

@@rowcount In Xp_sendmail

Aug 17, 2000

I am trying to put the result of the number of lines of data transferred, in a mail message. In a query, i get the result but i am having trouble displaying the result in xp_sendmail. Any help and/or code will be appreciated.
Thanks

View 2 Replies View Related

Rowcount Of Al Tables In Db

Aug 2, 2002

Is there a script someone knows of which could give me the rowcounts of all the tables in a database?

thanks a lot!

View 2 Replies View Related

Rowcount In Tables

Jul 2, 2004

Can someone throw light on how to get the rowcount of a table that is stored in any system tables? I want to get tablename and rowcount for all user tables in a database in a query. Is there anyway other than count(*)?

Thanks
Vinnie

View 10 Replies View Related

Max Rowcount On Fields

Jan 21, 2005

I have an sp that returns data to a client application. I wonder how I'd go about doing the following: I need to implement a maximum amount of rows on a combination of several columns that are part of the resultset.

fe; Col001, Col002, Col003 are the result, the unique count of Col001 and Col002 are two;

Col001, Col002, Col003
1, 'aa', 'someOtherValue'
1, 'aa', 'someThingElse'
1, 'aa', 'ratherSillyActually'
2, 'aa', '...'

I'd return:
1, 'aa', 'someOtherValue'
1, 'aa', 'someThingElse'
2, 'aa', '...'

Any idea's?

View 14 Replies View Related

@@RowCount Problem

Mar 9, 2004

Hi I'm opening a RecordSet using the following code :

declare tcrl cursor FAST_FORWARD for SELECT TSample.ISmpCode
FROM TCertResults TSample
WHERE (TSample.ISmpShortCode ='24/12359')

Open trcl

What I want to be able to get a count of this recordset. Been thru the TSQL help and it's pointing me toward the @@RowCount command but I can't seem to get this working.

Any help would be apprieciated

View 14 Replies View Related

@@ROWCOUNT Issue

Mar 31, 2006

Hi,
I ran the following code and got @rows to display the value 1 - I guess it should display 0 because the IF statement returns no rows of course - So why is it displaying 1?

DECLARE @ERRORS INT
SELECT 5,10,15
IF @@ERROR > 0
SET @ERRORS=1
ELSE
SET @ERRORS=0
SELECT 'ROW_Count', @@ROWCOUNT --> shows 1 !!

View 3 Replies View Related

Rowcount, Rowsize

Sep 5, 2007

Trying to get the rowcount, rowsize for every table in everydatabase?
I'm getting the same tables from the same db. anyone ideas how to fix it?





declare @db varchar(40)
declare @sql varchar(8000)
declare @cursor varchar(8000)
declare @table_name varchar(60)


declare a cursor for

select name from master..sysdatabases



open a

fetch a into @db

while @@fetch_status = 0

begin
print ''
set @sql = 'use [' + @db + ']'
print @sql
exec (@sql)

declare b cursor for
select table_name from information_schema.tables
where table_type = 'base table'
and table_schema = 'dbo'
and table_name not like 'dbo.%'

open b
fetch next from b into @table_name
while @@fetch_status = 0
begin

select @cursor = 'exec sp_spaceused ' + '[' + @table_name + ']'
print @cursor
-- exec (@cursor)

fetch next from b into @table_name
end
close b
deallocate b



fetch next from a into @db
end

close a
deallocate a


=============================
http://www.sqlserverstudy.com

View 1 Replies View Related

@@ROWCOUNT Support???

May 4, 2006

I am trying to work a statement like the below - but am getting an error - I assume that @@ROWCOUNT is not supported?



UPDATE MobileInvoiceImport SET OrderDetailID = '123', QuantityReceived = '66' WHERE OrderDetailID = '123'

IF @@ROWCOUNT = 0

INSERT INTO MobileInvoiceImport (OrderDetailID, QuantityReceived) VALUES('123','1')

View 1 Replies View Related

RowCount Or Equivalent

Aug 22, 2007

I have a query that returns a set of rows - sorted by part#. On the report I can hide the duplicates (part#). How can I test the part# so that whenever a new part# starts I can reverse image the whole l line. I have not defined any groups. Is this a must?

View 2 Replies View Related

Use Of @@ROWCOUNT Variable

Oct 8, 2007

Hi all,
I am using @@ROWCOUNT variable in one of my stored procedures to get the count of rows affected. This stored procedure is invoked in a web application which is hosted on a server. This web application invokes many other stored procedures and is used simultaneously by many users.
Since @@ROWCOUNT is a global variable which is updated each time a select/insert/delete statement is run on the server, I have a doubt whether using this varible will result in any synchronization issues. I would like to know more about the scope of this variable and the impact of using it in a web application where multiple users can run different stored procs concurrently.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved