Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VIEWS 1

Status
Not open for further replies.

GCM06

Programmer
Mar 21, 2006
10
0
0
CA
hi guys below I have the following code. The problem that I am having is that for totalpts, I will like to get the accumulation but instead I get null values. Any ideas?
by the way all the column's data types are ints.

CREATE VIEW dbo.Calculate
AS
SELECT ptage =
CASE
WHEN age <= 35 THEN 0
WHEN age <= 40 THEN 8
END,
'pttrus' =
CASE
WHEN trus < 40 THEN 78
WHEN trus >= 40 and trus < 55 THEN 59
END,
'ptpsa' =
CASE
WHEN psa < 4 THEN 0
WHEN psa >= 4 AND psa <10 THEN 68
END,
'totalpts' = ptage + ptpsa + pttrus
FROM dbo.Risk

Thanks in advance,
GC
 
try:

CREATE VIEW dbo.Calculate
AS
SELECT ptage =
CASE
WHEN age <= 35 THEN 0
WHEN age <= 40 THEN 8
END,
'pttrus' =
CASE
WHEN trus < 40 THEN 78
WHEN trus >= 40 and trus < 55 THEN 59
END,
'ptpsa' =
CASE
WHEN psa < 4 THEN 0
WHEN psa >= 4 AND psa <10 THEN 68
END,
(ptage + ptpsa + pttrus) as totalpts
FROM dbo.Risk


Known is handfull, Unknown is worldfull
 
Thanks for replying but It still gives me a null value.
 
hi, sorry my mistake, didnt read it properly.

try this:


select
*,
(ptage + ptpsa + pttrus) as totalpts
from
(
SELECT ptage =
CASE
WHEN age <= 35 THEN 0
WHEN age <= 40 THEN 8
END,
'pttrus' =
CASE
WHEN trus < 40 THEN 78
WHEN trus >= 40 and trus < 55 THEN 59
END,
'ptpsa' =
CASE
WHEN psa < 4 THEN 0
WHEN psa >= 4 AND psa <10 THEN 68
END,

FROM dbo.Risk
)Dtable1


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top