Need a T-SQL String
Posted on 2003-11-29
I am new to T-SQL. Been a programmer for VB-Access only. Got an urgent assignment on SQL-2000 for stored procedure but not familiar with T-SQL. Need to have the complete -TSQL string to put into the stored procedure
I need a summary from a table but an analysis of certains fields are required.
Type Amount FactorA FactorB Status
A 1200 -0.98 0.70 1
A 1400 0.80 0.78 1
A 1100 -0.98 -0.78 -1
B 1400 0.92 -0.78 1
B 1350 -0.89 -0.66 -0.5
From the table above,Type will only be A or B. FactorA, FactorB and Status can be either positive or negative.
If Type is A then TOTAL = Amount * FactorA * Status
If Type is B then TOTAL = Amount * FactorB * Status
The summary that I need is very simple. It is an eight-line summary of TOTAL
Type A, Positive Status, Positive factor
Type A, Positive Status, Negative factor
Type A, Negative Status, Positive factor
Type A, Negative Status, Negative factor
Type B, Positive Status, Positive factor
Type B, Positive Status, Negative factor
Type B, Negative Status, Positive factor
Type B, Negative Status, Negative factor
The table can have thousands of rows. The calculations/query has to be efficient and fast as an auto-calculation is required every 30seconds. I need to use the results and put into recordset for further analysis.