2 Replies - 456 Views - Last Post: 18 June 2016 - 06:09 AM

#1 dag72  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 197
  • Joined: 02-March 11

Altering existing table

Posted 18 June 2016 - 06:00 AM

I have altered an existing 'Employees' table to include a computed column, 'Age'. This works well but I now want to update this with the following code
 
        Age AS
          CASE
	    WHEN DATEDIFF(yy,BirthDate,CURRENT_TIMESTAMP) <= 40
		THEN 'Younger'
		WHEN DATEDIFF(yy,BirthDate,CURRENT_TIMESTAMP) > 50
		THEN 'Older'
		ELSE 'Middle Age'
	   END,



This works if I create a new table with this as in
 
Age AS

          CASE
	    WHEN DATEDIFF(yy,BirthDate,CURRENT_TIMESTAMP) <= 40
		THEN 'Younger'
		WHEN DATEDIFF(yy,BirthDate,CURRENT_TIMESTAMP) > 50
		THEN 'Older'
		ELSE 'Middle Age'
	   END,



I am using the UPDATE Employees SET Age AS CASE...But syntax error near 'AS'. Any suggestion please.
Many thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Altering existing table

#2 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6340
  • View blog
  • Posts: 25,565
  • Joined: 12-December 12

Re: Altering existing table

Posted 18 June 2016 - 06:05 AM

.. SET Age = (CASE .. END)
Was This Post Helpful? 1
  • +
  • -

#3 dag72  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 197
  • Joined: 02-March 11

Re: Altering existing table

Posted 18 June 2016 - 06:09 AM

Great, many thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1