Link to home
Start Free TrialLog in
Avatar of Wedmore
Wedmore

asked on

SQL view - indexing help

We get a datafile from a vendor which I want to use for a view and create my own "summary" columns based on multiple columns.  

CASE WHEN LEFT(Status, 2) = "EM" OR Emergency = "Y" THEN "Emergency" ELSE "Standard" END AS 'Recordstatus'

(this is somewhat simplified)

That way the users in Access can simply say "Where recordstatus = 'Emergency' " and it will pull all the necessary combinations.

My question is, should I put an index on the Emergency and the Status column - will that have an effect on the query performance?  

Should it be a combined index or should each column have a separate index?

ASKER CERTIFIED SOLUTION
Avatar of jesusaflores
jesusaflores

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why not create a calculated column that handles the CASE statement and provides you with the single column with that result.  Then put that as an indexed column.
Avatar of Wedmore
Wedmore

ASKER

I always thought calculated columns should never be stored in a table.
There is a very wise bit of advise regarding databases, tables, and virtually everything else in life:
Never use "always" and always avoid using "never".

If it is the solution to your problem and, in fact, the best solution to your problem, why would you not do it?  Just to conform to an academic rule? ;-)
Can you put the whole SELECT query to advise you better index?

Above statement is part of WHERE clause or SELECT clause?

What is your performance priority? Better data manipulation or better retrieval?

If I get these inputs then I hope that I can help you better...
Avatar of Wedmore

ASKER

The above statement would be part of the SELECT clause.  The real question is that since I cant index columns in a view, would indexing the columns separately or combined make a difference.

Priority is data retrieval.
You say that you get a data file from a vendor and, apparently, you are loading that data into a SQL Server database which you then link to from Access.  If that is the case, then why can't you add the calculated column to the SQL Server table into which you load the data file and then put an index on that calculated column?  Also, you could add multiple indexes on the SQL Server table (e.g. on Status, Emergency, and the combination of both of those columns) without even having to do the calculated column.  That should allow you to access the data, from Access, via a SQL Query.

For that matter, couldn't you put the query in a stored procedure in the SQL Server database and then execute the stored proc from your Access front end?

Pulling the data from a stored proc on SQL Server would probably be the fastest, having the data and the indexes on SQL Server would probably be next fastest.