Manas Kumar
Manas Kumar

Reputation: 35

SET Date in Column A of type TIMESTAMP in DB2

I am running following DB2 query:

UPDATE Table
SET DATE(COLA) = '2017-03-31'
WHERE DATE(COLA) = '2017-03-29'; 

COLA is of type TIMESTAMP.

Sample Value:

COLA:
2017-03-29-00.00.00.000000

Expected Updated Value:

COLA:
2017-03-31-00.00.00.000000

When I am running above query, I am getting

SQL Code SQLCODE = -104,ERROR: ILLEGAL SYMBOL "(". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: = .

Could anyone help me out for this scenario?

Thanks a lot!

Upvotes: 2

Views: 26242

Answers (2)

Esperento57
Esperento57

Reputation: 17472

just do it:

UPDATE Table
SET COLA = '2017-03-31-00.00.00.000000'
WHERE DATE(COLA) = '2017-03-29'; 

Upvotes: 2

Dan Field
Dan Field

Reputation: 21641

I believe your problem is in the SET portion. Try this:

UPDATE Table
SET COLA = DATE('2017-03-31') -- TIMESTAMP ('2017-03-31-00.00.00.000000') 
WHERE DATE(COLA) = '2017-03-29'; 

You want to update the column, not update the result of a function performed on the column.

Upvotes: 4

Related Questions