Unix Technical Forum

Reusing a generated column to avoid over processing

This is a discussion on Reusing a generated column to avoid over processing within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, I'm constructing a query that will performs a lot o datetime calculumns to generate columns. All that operations ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:43 PM
brazil.mg.marcus.vinicius.lima
 
Posts: n/a
Default Reusing a generated column to avoid over processing

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:43 PM
Roy Harvey (SQL Server MVP)
 
Posts: n/a
Default Re: Reusing a generated column to avoid over processing

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 expression> as 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"
<marcvlima@gmail.com> wrote:

>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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:43 PM
Roy Harvey (SQL Server MVP)
 
Posts: n/a
Default Re: Reusing a generated column to avoid over processing

>
>> 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 expression> as 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:39 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com