sql server new users:
I am creating a VIEW, and in it I can successfully create a column named
YTD_OSO. The data in this column is created by doing calculations on two
other fields that are money-type (in another test they were float). So
far, so good. See snip of code below:
CASE
WHEN aipdn.D017_all.YTD_TotOrdAmt > 0 then (aipdn.D017_all.YTD_StkOrdAmt /
aipdn.D017_all.YTD_TotOrdAmt * 100)
ELSE 0
END AS YTD_OSO
However, if I add more to try to refer to the value of YTD_OSO any further,
I run into problems. First, if I refer to the column name WITHOUT QUOTES
around it, Query Analyzer tells me that 'YTD_OSO' is an invalid name and
won't make my VIEW.
If I put quotes around the column name, the VIEW is created, but when I try
to view the results I get the message:
"Syntax error converting the varchar value 'YTD_OSO' to a column of data
type int."
I am ASSUMING the YTD_OSO column that is created is of some numeric type
when it's created, being it contains only numbers (money values, actually).
If not, is there some way to force it as a money-type field? or something
numeric? Or am I not correctly referring to the column in my later portion
of the query (see below)?
CASE
WHEN 60 < YTD_OSO AND YTD_OSO < 90 THEN ((YTD_OSO * .01) * 100) - 60
WHEN YTD_OSO > 90 THEN 30
ELSE 0
END AS BASEPOINTS
(I've tried using 'YTD_OSO' (which gives error on run about varchar value
and data type int), and without quotes or using [ ] or # # says YTD_OSO is
an invalid name!
Any idea where the problem is here?