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!

Decode Function

Status
Not open for further replies.

LeighDreyer

Programmer
Mar 4, 2003
16
0
0
GB
Tryint to check if a persons age is over 65 if so place a Y in table else place a N in table this is my attempts with no luck

Method 1
DECODE(ROUND((F.TODAYS_DATE - C.DATE_OF_BIRTH) / 365) AS "AGE"

Method 2
Decode(Sign(65-ROUND((F.TODAYS_DATE - C.DATE_OF_BIRTH) / 365)), 1, N, Y )

anyone know how to do this ?
 
Code:
UPDATE table_name
SET IsOver65 = CASE WHEN date_of_birth < DATEADD(yy, -65, getdate()) THEN 'Y' ELSE 'N' END
--James
 
case
when datediff(day, c.date_of_birth, f.todays_date)/365.25 >= 65 then 'Y'
else 'N' end
 
Tried the Datediff one and keep getting error on Datediff saying Invalid Coloumn name ????

case
when datediff(DAY, C.DATE_OF_BIRTH, F.TODAYS_DATE)/365.25 >= 65 then 'Y'
else 'N' end
 
maybe I should have said that I am not performing an update it is inside a select Statement as below

SELECT A.NAME AS &quot;WARD NAME&quot;,
F.TODAYS_DATE AS &quot;DATE&quot;,
DECODE(C.SEXXX_REFNO,'250564','M','250416', 'F') AS &quot;SEX&quot;,
(ROUND((F.TODAYS_DATE - C.DATE_OF_BIRTH) / 365) AS &quot;AGE&quot;

need to convert it in here if possible ?.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top