views:

126

answers:

4

I have a view from which I am selecting three columns. Of these three columns, one of them contains the OS version.

I want to create an additional column in the result which checks the OS Version. If the OS Version is less than 5.1 it should return 'Bad', if it is greater than that it should return 'Good'.

Any ideas about how to add this additional column?

+4  A: 

Try this...

Select
    Col1,
    Col2,
    OS,
    OSResult = Case When OS < 5.1 Then 'Bad' Else 'Good' End
From
    Table
Chalkey
You were first, +1. But add an alias to the last column
colithium
It has an alias... OSResult. You can alias columns by using the '=' symbol, its an alternative to 'as'.
Chalkey
A: 

Assuming the column cannot be NULL:

SELECT  ...
        CASE WHEN OS_VERSION < '5.1' THEN 'BAD' ELSE 'GOOD' END AS IsVersionGood
FROM    ...
van
A: 

Hi,

select OS_Version, case when OS_Version <= 5.1 then 'Bad' else 'Good' end
from ...

Hope this can help.

This works but is not a computed column.
Adamski
+2  A: 

You could also add it as a computed column to the table definition if you wanted e.g

ALTER TABLE dbo.OS ADD
    VersionOk  AS (case when [OS]<(5.1) then 'bad' else 'good' end)
Chris W