All Forums Analytics
zxz118 1 post Joined 10/10
26 Oct 2010
Temporary variable store in SQL

Is there any way to let SQL aware of a temporary variable which value varies from record to record? The job needs to be done is following:

Suppose C1 and C2 are two columns in the table, a1 and a2 are two constants. f1(x) to fn(x) is n transformation functions. want to get:

Is there any way that SQL can first remember a variable y=C1*a1+C2*a2 for each record, then directly use this y to do the select:

I know one way to do this is by a temporary table. But does Teradata has such build-in functionality to calculate y first, then do the aggregation on the fly?


toddb 13 posts Joined 10/10
27 Oct 2010

Not sure if this is what you are looking for, but you could create a view and define y as C1*a1+C2*a2 and then just reference your view in the select. If you are looking to keep changing y then you just change your view to the new formula.

You must sign in to leave a comment.