Showing posts with label evaluating. Show all posts
Showing posts with label evaluating. Show all posts

Wednesday, March 28, 2012

Replacing a cursor

I am currently evaluating the performance of an application which relies heavily on cursors. Below is an code example. I am looking for some good performance gains, is this the best method of updating rows of data?

DECLARE @.PAlloc_TimeID as int
DECLARE @.PAlloc_UniqueID as int
DECLARE PAlloc CURSOR FOR
SELECT TimeID,
UniqueID
FROM #PMatch
GROUP BY TimeID, UniqueID
HAVING SUM(Active) > 1

OPEN PAlloc
FETCH NEXT FROM PAlloc INTO @.PAlloc_TimeID , @.PAlloc_UniqueID
WHILE (@.@.FETCH_STATUS = 0)
BEGIN

UPDATE P
SET Active = 0
FROM #PMatch P
WHERE P.TimeID = @.PAlloc_TimeID
AND P.UniqueID = @.PAlloc_UniqueID
AND P.ElementID > (
SELECT MIN(ElementID)
FROM #PMatch
WHERE TimeID = @.PAlloc_TimeID
AND UniqueID = @.PAlloc_UniqueID)


FETCH NEXT FROM PAlloc INTO @.PAlloc_TimeID , @.PAlloc_UniqueID
END
CLOSE PAlloc
DEALLOCATE PAlloc

Normally, using a CURSOR is NOT the best way to update data. (However, in a few situations, it may be necessary.)

A set based operation (UPDATE) is usually the 'best' way to update. Consider if your process above could be re-written as a single UPDATE statement, perhaps using one or more sub-queries. (It might be easier than you think.)

|||

Yes... Arnie is right, It can be replace with single Update

Statement. But if the Database is gigantic then Updating in a single statement

is not preferred.

|||

u'll be able to write this query in one (or more) update statement(s)...or use a case in update statement.... most of the times u wont need a sursor at all.... and i guess even for a large database in this is a better solution..., as cursor on a large table will block resources for long...

sql

Monday, March 26, 2012

replacement for report manager

Hi!
I am evaluating how far i can go in implementing repoting features of SRS in
my program.
I want to be able to write a Windows form (in C#) that has a grid/list
containing all the reports that I have made. The list may have been
previously enterd into the database along with other information needed to
run the particular report.
I want to be able to select in the grid/list(e.g. using a check box) which
reports to run, and what format to render each individual report, as well as
other parameters.
Is the Report Manager that extensible? Is it possible to create this sort of
replacement for Report Manager from C#?
I am using VS2005 and SRS 2005.
Thanks in advance!It is absolutely possible... I have written a report for a customer which
searches the reporting services met data database and returns a list of
reports which match the search criteria the customer wants.. It creates a
report which displays the report name, directory and description... Each
report name is a hot link to run the report... This was done in a report!~
Using a programming language you can do anything you wish... There is a
ReportViewer control ( Search for ReportViewer in Books on line.) that you
can use..
There are sample programs in the SQL directory /90 subdirectory which will
help get you started...
Reporting Services is also just a DotNet Web service, with an entire API
which can you call from your program as well.. It is the same API that MS
uses in the Report Manager..
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC
I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.
"PacMan" wrote:
> Hi!
> I am evaluating how far i can go in implementing repoting features of SRS in
> my program.
> I want to be able to write a Windows form (in C#) that has a grid/list
> containing all the reports that I have made. The list may have been
> previously enterd into the database along with other information needed to
> run the particular report.
> I want to be able to select in the grid/list(e.g. using a check box) which
> reports to run, and what format to render each individual report, as well as
> other parameters.
> Is the Report Manager that extensible? Is it possible to create this sort of
> replacement for Report Manager from C#?
> I am using VS2005 and SRS 2005.
> Thanks in advance!