By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

Reusing a generated column to avoid over processing

P: n/a
Hi,

I'm constructing a query that will performs a lot o datetime
calculumns to generate columns.
All that operations are dependent of a base calculum that is performed
on the query and its result is stored in a columna returned.

I wanna find a way of reusing this generated column, to avoid
reprocessing that calculumn to perform the other operations, cause
that query will be used in a critical application, and all saving is
few.

Thanks a lot.

Oct 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
One approach is to use a view. Another is to use a derived table. For
SQL Server 2005 there is a third alternative, a Common Table
Expression (CTE).

All three alternatives require writing the query that returns the
computed column and then using that query in any of the three ways. So
we could have something like:

WITH Example AS
(SELECT A, B, C, <complex expressionas Complex
FROM X)
SELECT *
FROM Example
WHERE Complex = '20071225'

Roy Harvey
Beacon Falls, CT

On Mon, 22 Oct 2007 06:06:17 -0700, "brazil.mg.marcus.vinicius.lima"
<ma*******@gmail.comwrote:
>Hi,

I'm constructing a query that will performs a lot o datetime
calculumns to generate columns.
All that operations are dependent of a base calculum that is performed
on the query and its result is stored in a columna returned.

I wanna find a way of reusing this generated column, to avoid
reprocessing that calculumn to perform the other operations, cause
that query will be used in a critical application, and all saving is
few.

Thanks a lot.
Oct 22 '07 #2

P: n/a
>
>One approach is to use a view. Another is to use a derived table. For
SQL Server 2005 there is a third alternative, a Common Table
Expression (CTE).

All three alternatives require writing the query that returns the
computed column and then using that query in any of the three ways. So
we could have something like:

WITH Example AS
(SELECT A, B, C, <complex expressionas Complex
FROM X)
SELECT *
FROM Example
WHERE Complex = '20071225'
>I thought to divide in steps the performation of the calculumns.
In the first step create a view that execute the basic calculation,
and create another views that reuse the alread done work.

But its seems to be very strange, cause its not a elegant solution.
Using views on views is one way to do it, but with the new feature of
Common Table Expression (CTE) in SQL Server 2005 we can avoid that.
You can have more than one CTE prefixing a command, and the succeeding
ones can reference the preceding ones. That means the nesting can all
be in the one command, much cleaner than views on views.

Roy Harvey
Beacon Falls, CT
Oct 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.