Index Performance Tuning Help

Oct 22, 2007

I'm using the Database Engine Tuning Advisor to do some performance evaluation on my database. I have one particular table that will potentially have a couple million rows. but this may not occur for a few months to a year from now.

when i run the advisor with 1.5 million rows, it recommends that i add an index across all columns in this table (covering index) for an estimated 91% improvement. when i run it with 1500 rows in it, it recommends that i add an index on 2 key columns for an 8% improvement.

how should i reconcile this? can i have both and what does that do to performance?

View 17 Replies


ADVERTISEMENT

Performance Tuning Using Index. How To Force The Query Engine To Use It?

Nov 14, 2007

Hello all.
I have the following table

Create Table Item(
I_AssetCode NVarChar(40) Primary Key NOT NULL,
I_Name NVarChar(160),
I_BC nvarchar(20),
I_Company nvarchar(20)
);

Create Index ind_Item_Name on Item(I_Name);
Create Index ind_Item_BC on Item(I_BC);
Create Index ind_Item_Company on Item(I_Company);

It is populated with 50 000 records.
Searching on indexed columns is fast, but I've run into the following problem:
I need to get all distinct companies in the table.
I've tried with these two queries, but they both are very slow!

1. "select I_Company from item group by I_Company " - This one takes 19 seconds

2. "select distinct(I_Company) from item" -This one takes 29 secons

When I ran them through the SQL Management Studio and checked the performance plan, I saw that the second one doesn't use index at all ! So I focused on the first...
The first one used index (it took it 15% of the time), but then it ran the "stream aggregate" which took 85% of the time !
Actully 15% of 19 seconds - about 2 seconds is pretty much enough for me. But it looks that aggregate function is run for nothing!
So is it possible to force the query engine of the SSCE not to run it, since there is actually no aggregate functions in my select clause?
According to SQL CE Books online:
Group By


"Specifies the groups (equivalence classes) that output rows are to be placed in. If aggregate functions are included in the SELECT clause <select list>, the GROUP BY clause calculates a summary value for each group."
It seems the aggregate is run every time, not only when there is an aggregate function.

Is this a bug?

Thanks in advance,
TipoMan

View 4 Replies View Related

INDEX TUNING

Jun 7, 2001

I want to use the Index tuning wizard on some of my tables. Is it OK if I use when people are on the server or to do it during off-pick period. Thanks!!!

View 1 Replies View Related

Index Tuning

Nov 29, 1999

Other than the SQL Server 7.0 Index Tuner wizard (which isn't suggesting anything). Is there a 3rd party Index Tuner piece of software out there? Or is there something special that needs ot be done to get the SQL Index Tuner to work?

View 3 Replies View Related

Index Tuning

Jul 26, 2007

for what purpose we are splitting the non-clustered index into 3 instead of 1

create index si_acct_info_dtl_INDX1 on si_acct_info_dtl(account_code, ctrl_acct_type)
create index si_doc_hdrfk_ci_acct_info_dtl on si_acct_info_dtl(tran_ou, tran_type, tran_no)


whether index rebuit everycolumn when search is given????.if we build the index in one
statement like this:create index si_acct on si_acct_info_dtl(batch_id)
create index si_acct_info_dtl_guid on si_acct_info_dtl(batch_id,account_code, ctrl_acct_type,tran_ou, tran_type, tran_no)

View 4 Replies View Related

Index Tuning

Apr 22, 2008

Hi,

Our reporting tool dynamically creates tables and fields based upon Excel spreadsheets that are imported. To improve query performance, we are attempting to create indices on these tables automatically. The problem we are facing is that the tool allows the user to group the data by a whole range of fields when generating reports, therefore making it hard to decide what indices to create.

So, as an example, we have a table that has 10 VARCHAR(250) fields (the default size for text based fields in the tool), each of which could potentially be in the group by clause, and 15 numeric fields on which calculations will be carried out.

Is there a single index that we can create dynamically that would improve performance for all potential queries that may be generated? Such as an index that contains all the 10 VARCHAR(250) fields, and the numeric values as Included Columns?

If so, what effect does the order of the fields in the index have, ie we have some fields that have a lot of distinct values and some that have only a few. Which ones should appear higher in the list?

Any help would be greatly appreciated.

James

View 5 Replies View Related

Performance Tuning

Jul 9, 2001

Hey all,

I am interested in finding out if anyone out there has experience with extremely high-performance SQL Server applications. The I/O needs of my database server are growing very quickly, and I am on the verge of launching a major upgrade project.

We have done all the standard tuning tasks: proper indexing, stored procedure tuning, etc... and are running on good small-server scale hardware ( dual PIII 700s, 1G RAM, but no RAID). The only path I can see to achieving higher performance are:

- lots of RAID, perhaps on a SAN.
- server upgrade, maybe 4 proc? I've been looking at RAIDZONEs and Netfinity's
- data partitioning ( I REALLY want to avoid this if I can! )

What do you do when you need Major Enterprise scale database performance from SQL Server? I've found lots of resources for Oracle and DB2, but I can't find many case studies for serious SQL Server installations.

Help!

-Dave

View 1 Replies View Related

Performance Tuning

Jul 18, 2000

Hi,
does the upgradition SQL Server 6.5 to 7.0 will simply solve some problems which we are facing currently like ODBC errors Insert failed and update failed and also supporting more users ?
We have Access front end to SQL Server backend, so do we need to touch code in front end for optimizations ?

Can any pls guide me on this

Thanks

View 3 Replies View Related

Got The Pb Reg Performance Tuning

Nov 15, 1999

Hi, i am working on sql server 6.5 version.actually this is developed just one year back. but now the system is almost dead(low performance).i think the reasons r database design,networking,hardware etc.is it correct. and how to rectify these errors. i am suggesting that upgradation is the best option.so pl give the suggestions asap.
Thanx
Janreddy

View 1 Replies View Related

Performance Tuning?

Feb 27, 2001

Hi,

Anyone know any articles on Performance Tuning on the web? I'm trying to monitor one of my production boxes and don't know which counters to use.

Thanks!

Joe R.

View 4 Replies View Related

Performance Tuning

Feb 13, 2007

Hi All,

What are some of the things i can do to improve query performance if the querey performance is realatively slow today compared to yesterday's performance:
Here are some of things i looked at:
-updating statistics
-checking the execution plan
-DBCC showcontig

View 5 Replies View Related

Tuning Performance Of DB

May 17, 2007

What all possible ways there have been to maximizing performance of database?

View 4 Replies View Related

Performance Tuning

Aug 23, 2007

how to increase performance through management studio
except making indexes

View 4 Replies View Related

Performance Tuning

Mar 7, 2008

Hi Guys I need someone to assist me in having full understanding of what performance turning is. My Challenge is interpreting the System Monitor Graph of Performance tools.

I needed to know what does the value on vertical axis represent, while there is non on the horizontal axis rather I have Last, Average, Minimum, Maximum and Duration; Please What does all this value stands for, I indeed observe that when I click on any of the counters selected the value changes, therefore kindly assist me so that I can make meaning of this. Apart from all this please assist me with any material that can explain performance tuning to my maximum benefit, thanks in anticipation.

Pls Check below sample of the file is attached

View 1 Replies View Related

Performance Tuning

Jun 11, 2008

Hi All,

I am new to this forum, would like to know about performance tuning methods in sql and which is the best site to read about it?

Thanks

View 5 Replies View Related

Performance Tuning

Mar 13, 2007

Hi experts,
I've run sql profiler with %processor time counter .it showed a large value of 75
so please give me steps to tune the long running query with high cpu utilisation.


thanks in advance

View 20 Replies View Related

Performance Tuning

Aug 23, 2007

i just wanna know how to reduce the performance of the query
can any one pls help me in the gaining the performance of query
SELECT
tblBankruptcyInfo.MasterID,
tblBankruptcyInfo.bk_Case_Number

INTO #ActiveBK

FROM FNFBSDataMart.dbo.tblReferral tblReferral WITH (NOLOCK)
INNER JOIN FNFBSDataMart.dbo.tblBankruptcyInfo tblBankruptcyInfo WITH (NOLOCK)
ON tblReferral.RefID = tblBankruptcyInfo.RefID
AND tblReferral.CloseDate IS NULL
INNER JOIN FNFBSDataMart.dbo.tblSuperClientFile tblSuperClientFile WITH (NOLOCK)
ON tblReferral.ClientFileID = tblSuperClientFile.ClientFileID
AND tblSuperClientFile.SuperClientVendorID IN (1816,125,127,1706,766,1820,137,141,144,145,1593,1808,146,990,1745,149,1215,1854,1867)

GROUP BY
tblBankruptcyInfo.MasterID,
tblBankruptcyInfo.bk_Case_Number

View 6 Replies View Related

Performance Tuning Help Me

Nov 19, 2007

Hi all ,

I am doing performance tuning in sql

I have a query which it gives result in 70000 rows and time is taken 7 mints .

But i want one query is not more than 50000 row
my query is :-


SELECT
QPDMADM.LAR_OMEGA_TRANS_SUM.SOURCE_TRANSACTION_ID,
QPDMADM.LAR_OMEGA_TRANS_SUM.ORDER_DATE,
QPDMADM.LAR_OMEGA_TRANS_SUM.SHIP_DATE,
QPDMADM.LAR_OMEGA_TRANS_SUM.FISCAL_PERIOD,
QPDMADM.LAR_OMEGA_TRANS_SUM.DISCOUNT_AGREEMENT_ID,
QPDMADM.LAR_OMEGA_TRANS_SUM.PRODUCT_ID_07,
QPDMADM.LAR_OMEGA_TRANS_SUM.CUSTOMER_ID_14,
QPDMADM.LAR_OMEGA_TRANS_SUM.ISO_COUNTRY_CODE2,
QPDMADM.LAR_OMEGA_TRANS_SUM.ACCOUNT_TYPE_CODE,
QPDMADM.LAR_OMEGA_TRANS_SUM.END_USER_CUSTOMER_ID,
sum(QPDMADM.LAR_OMEGA_TRANS_SUM.NIA_AMT),
QPDMADM.LAR_OMEGA_TRANS_SUM.INDUSTRY_CLUSTER_CODE,
QPDMADM.LAR_OMEGA_TRANS_SUM.SOURCE_SYSTEM_ID,
QPDMADM.LAR_OMEGA_TRANS_SUM.LOAD_DATE
FROM
QPDMADM.LAR_OMEGA_TRANS_SUM
WHERE
(
QPDMADM.LAR_OMEGA_TRANS_SUM.FISCAL_PERIOD = '200712'
)
GROUP BY
QPDMADM.LAR_OMEGA_TRANS_SUM.SOURCE_TRANSACTION_ID,
QPDMADM.LAR_OMEGA_TRANS_SUM.ORDER_DATE,
QPDMADM.LAR_OMEGA_TRANS_SUM.SHIP_DATE,
QPDMADM.LAR_OMEGA_TRANS_SUM.FISCAL_PERIOD,
QPDMADM.LAR_OMEGA_TRANS_SUM.DISCOUNT_AGREEMENT_ID,
QPDMADM.LAR_OMEGA_TRANS_SUM.PRODUCT_ID_07,
QPDMADM.LAR_OMEGA_TRANS_SUM.CUSTOMER_ID_14,
QPDMADM.LAR_OMEGA_TRANS_SUM.ISO_COUNTRY_CODE2,
QPDMADM.LAR_OMEGA_TRANS_SUM.ACCOUNT_TYPE_CODE,
QPDMADM.LAR_OMEGA_TRANS_SUM.END_USER_CUSTOMER_ID,
QPDMADM.LAR_OMEGA_TRANS_SUM.INDUSTRY_CLUSTER_CODE,
QPDMADM.LAR_OMEGA_TRANS_SUM.SOURCE_SYSTEM_ID,
QPDMADM.LAR_OMEGA_TRANS_SUM.LOAD_DATE




Note:- FISCAL_PERIOD is index only


Thank & Regards,
Anil

View 2 Replies View Related

Index Tuning Errors

Jul 28, 2000

Eveytime I feed a query into the Index Tuner
I get the usefull message Error analyzing query (60)

What is it and how do I get round it

View 2 Replies View Related

Index Tuning Using Sql Script

May 2, 2003

Is it possible to achieve Index tuning using sql script within Query Analyser when being just a db_owner and not sysadmin.
In case the answer is yes, would you please provide any link to help or examples.

Thanks

View 8 Replies View Related

Index Tuning Wizard

Mar 31, 2006

Hi,

I wanted to use the Index Tuning Wizard to monitor the performance of a stored procedure but the option is greyed out. Is there a way to turn this functionality on, or does this indicate that this option is not installed ?

Thanks,
Jeff

View 1 Replies View Related

Index Tuning Wizard

Apr 17, 2007

hi all,
jusr read about index tuning wizard in BOL.. not sure about it enuff.. can anybody explain in what scenario we should use this wizard/

~~~Focus on problem, not solution~~~

View 5 Replies View Related

Index Tuning Wizard

Jul 20, 2005

HiI tried running ITW against one of our databases, and it came up with anumber of suggestions, but also filled the Application Log with messageslike:-The description for Event ID ( 4 ) in Source ( ITW ) could not be found. Itcontains the following insertion string(s):Error in Parsing Event:declare @P1 nvarchar(1)declare @P2 nvarchar(1)declare @P3 nvarchar(1)declare @P4 nvarchar(1)EXEC "dbo"."sp_get_RAO_indexW2K2" @P1 , @P2 , @P3 , @P4 .Does anyone know if this is serious (or indeed what it means at all)?There were no apparent errors in the ITW run.Chloe Crowder

View 1 Replies View Related

Index Tuning : ReportServer DB

Nov 1, 2007

Hi All!

I would like to try and increase the performance of the reportserver database. Im thinking of adding an index to dbo.catalog.itemID - before I break the database and subsequently kill the 200+ reports i spent ages writing, does anyone know of any problems doing this?

The reports seem to be a bit slow first run but speed up during the course of the day - the server generates about 1500 instances of reports each day (7 instances of reportmanager all pointing to the reportserver db). I primarily use precompiled storedprocedures to feed the datasets so this is why im thinking index tuning may help.

Any thoughts/comments are welcomed!

View 2 Replies View Related

Sql Server Performance Tuning

Feb 7, 2008

Hi,
   Can some one please send me the Sql Server 2005 Performance Tuning artilce links?
Thanks

View 1 Replies View Related

SQL Performance And Tuning Question

Apr 18, 2000

I have a problem that is more complex than the one that follows, but if someone can answer this question,
I believe I can take it from there in solving my real problem.

Why does:

create table #bbb (c int)
set nocount on
declare @a int
select @a = 1
while (@a < 5000)
begin
select @a = @a + 1
insert into #bbb values (@a)
end

run in about 2 seconds, while:

create table bbb (c int)
set nocount on
declare @a int
select @a = 1
while (@a < 5000)
begin
select @a = @a + 1
insert into bbb values (@a)
end

runs in about 20 seconds? (The only difference is that one uses a temp. table.)

What could I have configured incorrectly to cause this behavior?

Thanks in advance!

Palmer

View 6 Replies View Related

Basic Performance Tuning

Oct 5, 1999

Hi !

What are some basic tips and hints for better performance running SQL 7.0 ?


Thanx

View 1 Replies View Related

Performance Tuning Resources

Jun 13, 2000

Anybody have a suggestion on text books or other materials that deal with performance tuning in SQL 7.0. From what I have seen SQL 7.0 is far diffrent than 6.5. I'm specificaly interestd in information about query plans, profiler and what a table spool does.

View 1 Replies View Related

Performance Tuning On Views?

Aug 27, 2014

I have a query which retrieves data from 4-5 tables. To restrict the acess directly to the tables, views have been created on all these tables. These views are just select * from the tables. Two of these 5 tables have 700 Million and 8 Million rows respectively. And all the tables are having indexes. My issue here is that my query on views take three times more then the duration it takes to retrive data directly from tables. e.g. To retrieve 1 Miliion rows, it takes just 7-10 minutes on tables but on views it takes more than 30 minutes. When I check the query plan for both the options, I can see that indexes are being picked up but still the views are very slow.

Creating indexes on views is not feasible option for me as it requires DDL changes and so much testing efforts.

View 14 Replies View Related

SQL Server 2k Tuning And Performance

Feb 18, 2004

Hi, I am new to database admin. Actually, I really have no experience what so ever. My boss has asked me to do some tests on our sql server to find bottlenecks or whatever is causing our server to respond so slowly.

Any help would be, ugh helpful.

I am loking for tools or information that will help troubleshoot any problems with the ms sql server 2k. I have tried sql profiler, but I found myself lost, not knowing what to look for.

Thank you

View 4 Replies View Related

Performance Tuning Methods

Mar 16, 2004

Hello everyone:

Can anyone list the general performance tuning methods? Thanks a lot.

ZYT

View 1 Replies View Related

Challenges For Performance Tuning

May 5, 2008

Hi,

I have a stored procedure, I really need some one to help me for performance.

This stored procedure will generate dynamic sql and then paging depending on the @orderbystatement
@orderbystatement could be one column or multiple columns.

Join fields have indexes but execution plan still have hash match on Register table because a lot of duplicate records on
the columns of CalendarAcademicYearId and Worker.

The bottleneck is execution for dynamic sql statement with paging functionality. because all statement after set rowcount 0 only has 10 rows.

This performance task took me a few days and I still didn't get a good idea. Any tip will be appreciated.


Thanks.


Code Snippet

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_MyProc]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[usp_MyProc]
GO


CREATE PROCEDURE [dbo].[usp_MyProc]
@Dob DATETIME = NULL,
@CtrlWorkerNo NVARCHAR(20) = NULL,
@Factory NVARCHAR(MAX) = NULL,
@Position VARCHAR(25) = NULL,
@Gender NVARCHAR(10) = NULL,
@Year uniqueidentifier = NULL,
@FamilyName NVARCHAR(50) = NULL,
@GivenNames NVARCHAR(50) = NULL,
@FirstRow INT = NULL,
@MaxRows INT = NULL,
@IsWorker INT = NULL,
@IsAcStaff INT = NULL,
@Order NVARCHAR(255) = 'FamName , FirstName , DOB',
@RegisterStatus NVARCHAR(255) = NULL,
@PersonGuid VARCHAR(36) = NULL,
@IncludeStarted BIT = 0,
@IncludeHistorical BIT = 0,
@IncludeNoRegisters BIT = 0
AS
BEGIN

SET NOCOUNT ON;

CREATE TABLE #t
(Id INT Identity(1,1),EntityId uniqueidentifier)

SELECT @Factory = REPLACE(@Factory,',',''',''')
SELECT @RegisterStatus = REPLACE(@RegisterStatus,',',''',''')

DECLARE @RegisterYears INT
SET @RegisterYears = NULL

IF (@Factory IS NOT NULL )
OR (@Position IS NOT NULL)
OR (@Year IS NOT NULL)
OR (@RegisterStatus IS NOT NULL)
OR (@IsWorker = 1)
BEGIN
SELECT @RegisterYears = (SELECT DATEPART(year, getDate()))
DECLARE @RegisterYearsHistorical INT
SET @RegisterYearsHistorical = (SELECT HistoricalYears FROM Organisation)
IF (@IncludeHistorical = 0 AND @RegisterYearsHistorical IS NOT NULL AND @IsWorker = 1)
BEGIN
SET @RegisterYears = @RegisterYears - @RegisterYearsHistorical
END
ELSE IF (@IncludeHistorical = 1 OR @IsWorker IS NULL OR @IsWorker = 0)
BEGIN
SET @RegisterYears = NULL
END
END

DECLARE @OrderByStatement NVARCHAR(255)
SET @OrderByStatement = @Order
DECLARE @FactoryJoin nvarchar(1000)
SET @FactoryJoin = ''
IF (PATINDEX('%School%', @Order) > 0 OR @Factory IS NOT NULL)
BEGIN
SET @FactoryJoin = 'LEFT OUTER JOIN dbo.Factory AS Factory ON Worker.School = Factory.Code '
SET @OrderByStatement = REPLACE(@OrderByStatement, 'School', 'Factory.Code')
END

DECLARE @AddressJoin nvarchar(1000)
SET @AddressJoin = ''
IF (PATINDEX('%Suburb%', @Order) > 0)
BEGIN
SET @AddressJoin = 'LEFT OUTER JOIN dbo.hjEntityAddress EntityAddress ON Worker.EntityId=EntityAddress.EntityId AND(EntityAddress.AddressType=''Local'' ) ' +
'LEFT OUTER JOIN dbo.hjAddress [Address] ON EntityAddress.AddressId=[Address].AddressId '
SET @OrderByStatement = REPLACE(@OrderByStatement, 'Suburb', '[Address].Suburb')
END

DECLARE @MainContactJoin nvarchar(1000)
SET @MainContactJoin = ''
IF (PATINDEX('%MainContact%', @Order) > 0)
BEGIN
IF (PATINDEX('%DESC%', @Order) > 0)
BEGIN
SET @Order = REPLACE(@Order, ',MainContact', ' DESC,MainContact')
SET @OrderByStatement = @Order
END
SET @MainContactJoin = 'LEFT OUTER JOIN dbo.hjRelationship Related ON Person.EntityId = Related.EntityID1 AND Related.MainContact=1 AND Related.Active = 1 ' +
'LEFT OUTER JOIN dbo.hjPerson MainContact ON Related.EntityID2 = MainContact.EntityID '
SET @OrderByStatement = REPLACE(@OrderByStatement, 'MainContact', 'MainContact.')
END

DECLARE @IncNoRegister NVARCHAR(MAX)
SET @IncNoRegister = ''
IF (@IncludeNoRegisters = 0)
BEGIN
SET @IncNoRegister = '
INNER JOIN dbo.Register ON dbo.hjWorker.WorkerNo = dbo.Register.Worker
INNER JOIN dbo.YearTable ON dbo.YearTable.CalendarAcademicYearId = dbo.Register.
CalendarAcademicYearId


WHERE (dbo.Register.Factory IN ('''+ISNULL(@Factory, '')+'''))
AND ((dbo.Register.[CalendarAcademicYearId] = @CalendarAcademicYearId_) OR
(@CalendarAcademicYearId_ IS NULL))
AND ((dbo.Register.Position = @Position_) OR (@Position_ IS NULL))
AND ((DATEPART(yy, dbo.YearTable.StartDate) >= @RegisterYears_) OR (@RegisterYears_ IS
NULL) OR (dbo.YearTable.StartDate IS NULL))
AND ((dbo.Register.RegisterStatus IN ('''+ISNULL(@RegisterStatus, '')+''')) OR (@RegisterStatus_
IS NULL))'
END
ELSE
BEGIN
SET @IncNoRegister = '
LEFT JOIN dbo.Register ON dbo.hjWorker.WorkerNo = dbo.Register.Worker
LEFT JOIN dbo.YearTable ON dbo.YearTable.CalendarAcademicYearId = dbo.Register.
CalendarAcademicYearId


WHERE (dbo.Register.RegisterID IS NULL)
OR
(
((dbo.Register.Factory IN ('''+ISNULL(@Factory, '')+''')) OR (@Factory_ IS NULL) )
AND ((dbo.Register.[CalendarAcademicYearId] = @CalendarAcademicYearId_) OR
(@CalendarAcademicYearId_ IS NULL))
AND ((dbo.Register.Position = @Position_) OR (@Position_ IS NULL))
AND ((DATEPART(yy, dbo.YearTable.StartDate) >= @RegisterYears_) OR (@RegisterYears_ IS
NULL) OR (dbo.YearTable.StartDate IS NULL))
AND ((dbo.Register.RegisterStatus IN ('''+ISNULL(@RegisterStatus, '')+''')) OR (@RegisterStatus_
IS NULL))
)
'

END

DECLARE @StartedClause NVARCHAR(100)
SELECT @StartedClause = ''
IF @IncludeStarted = 0
SELECT @StartedClause = ' (Person.StartedDate IS NULL ) AND '

DECLARE @sql NVARCHAR(MAX)
SELECT @sql = N'
set rowcount ' + convert(varchar,@FirstRow + @MaxRows -1) + '
INSERT INTO #t
SELECT Entity.EntityId
FROM dbo.hjEntity Entity
INNER JOIN dbo.hjPerson Person ON Entity.EntityId=Person.EntityId
LEFT OUTER JOIN dbo.hjWorker Worker ON Worker.EntityId=Entity.EntityId '
+ @FactoryJoin
+ @MainContactJoin
+ @AddressJoin
+ '
WHERE Entity.EntityID IN
(
SELECT dbo.hjEntity.EntityID
FROM dbo.hjEntity
LEFT OUTER JOIN dbo.hjWorker ON dbo.hjWorker.EntityId=dbo.hjEntity.EntityId
' + @IncNoRegister + '
)
AND
(' + @StartedClause + '((Person.IsWorker=@IsWorker_ )OR (@IsWorker_ IS NULL))
AND((Person.IsAcStaff=@IsAcStaff_) OR (@IsAcStaff_ IS NULL))
AND((Person.FamName like @FamilyName_) OR (@FamilyName_ IS NULL) )
AND((Person.FirstName like @GivenNames_) OR (Person.PrefName LIKE @GivenNames_) OR
(Person.SecName LIKE @GivenNames_) OR (@GivenNames_ IS NULL) )
AND((Person.DOB LIKE @Dob_) OR (@Dob_ IS NULL) )
AND((Worker.CtrlWorkerNo like @CtrlWorkerNo_) OR (@CtrlWorkerNo_ IS NULL) )
AND((Person.Gender LIKE @Gender_) OR (@Gender_ IS NULL) )
AND((Person.EntityId != @PersonGuid_) OR (@PersonGuid_ IS NULL) )
) ORDER BY ' + @OrderByStatement

print @sql

EXEC sp_executesql @sql,N'@Factory_ NVARCHAR(10),@CalendarAcademicYearId_ uniqueidentifier,@RegisterStatus_ VARCHAR(50),@IsWorker_ INT,@IsAcStaff_ INT,@FamilyName_ NVARCHAR(50),@GivenNames_ NVARCHAR(50),@Dob_ DATETIME,@CtrlWorkerNo_ NVARCHAR(20),@Gender_ NVARCHAR(10),@PersonGuid_ VARCHAR(36),@FirstRow_ INT, @MaxRows_ INT, @RegisterYears_ INT, @Position_ VARCHAR(25)
',@Dob_=@Dob,@CtrlWorkerNo_=@CtrlWorkerNo,@Factory_=@Factory,@Gender_=@Gender,@CalendarAcademicYearId_=@Year,@RegisterStatus_=@RegisterStatus,@FamilyName_=@FamilyName,@GivenNames_=@GivenNames,@IsWorker_=@IsWorker,@IsAcStaff_=@IsAcStaff,@PersonGuid_=@PersonGuid,@FirstRow_=@FirstRow,@MaxRows_=@MaxRows,@RegisterYears_=@RegisterYears,@Position_=@Position

set rowcount 0


SELECT
Entity.EntityId,
Person.Title,
Person.FamName,
Person.FirstName,
Person.SecName,
Person.PrefName,
Person.DOB,
Person.Gender,
Person.EmploymentType,
Person.HighestSchoolLevel,
Person.HighestQualificationLevel,
Worker.School,
Factory.Name as SchoolName,
Worker.CtrlWorkerNo,
[Address].StreetNumber,
[Address].Street1,
[Address].Street2,
[Address].Suburb,
[Address].City,
[Address].State,
[Address].Postcode,
[Address].Country,
RelPerson.FamName as MainContactFamName,
RelPerson.FirstName as MainContactFirstName,
RelPerson.SecName as MainContactSecName,
RelPerson.PrefName as MainContactPrefName,
RelPerson.Title as MainContactTitle,
(SELECT COUNT(dbo.hjContactMethod.ContactMethodID) FROM dbo.hjContactMethod WHERE Worker.EntityId=dbo.hjContactMethod.EntityId AND(dbo.hjContactMethod.Priority='1' )) as ContactMethods,
Person.StartedDate
FROM dbo.hjEntity Entity
INNER JOIN #t t on Entity.EntityId = t.EntityId
INNER JOIN dbo.hjPerson Person ON Entity.EntityId=Person.EntityId
LEFT OUTER JOIN dbo.hjWorker Worker ON Worker.EntityId=Entity.EntityId
LEFT OUTER JOIN dbo.hjRelationship Relationship ON Worker.EntityId=Relationship.EntityId1 AND(Relationship.MainContact=1 )
LEFT OUTER JOIN dbo.hjEntity RelEntity ON Relationship.EntityId2=RelEntity.EntityId
LEFT OUTER JOIN dbo.hjPerson RelPerson ON RelEntity.EntityId=RelPerson.EntityId
LEFT OUTER JOIN dbo.hjEntityAddress EntityAddress ON Entity.EntityId=EntityAddress.EntityId AND(EntityAddress.AddressType='Local' )
LEFT OUTER JOIN dbo.hjAddress [Address] ON EntityAddress.AddressId=[Address].AddressId
LEFT OUTER JOIN dbo.Factory ON Factory.Code = Worker.School

WHERE (t.Id BETWEEN @FirstRow AND (@FirstRow + @MaxRows -1))
Order by t.Id


END

View 4 Replies View Related

Best Tool For Performance Tuning

Oct 17, 2006

Which is the best third party tool for SQL Server 2005 Performance Tuning/Optimization.



We purchased the Toad for SQL Server from Quest sofwater but it works only with dbo schemas....So if ur users were in schema xyz then it would not recognize it because they develop the tool for 2005 based on SQL Server 2000 where the schema ownesrhip is tied to the users.

View 1 Replies View Related







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