Home > front end >  Combine concat with substr in a sql query
Combine concat with substr in a sql query

Time:03-23

I am doing a sql query (in DB2) and I need to extract a date that is in the following form:

2022-01-01

In the Where condition I am using:

CONCAT(SUBSTR('$P!{FLIB}', 1, 4), SUBSTR('$P!{FLIB}', 5, 2), SUBSTR('$P!{FLIB}', 9, 2))

Where '$P!{FLIB}' is the date, but I get the following error: Invalid number of arguments for CONCAT function.

It should be like 20220101

CodePudding user response:

As said in a comment, a different approach is to first take the entire 'date' substring, and then replacing the '-' with empty string:

SELECT REPLACE(SUBSTR(x, 1, 10), '-', '') 
FROM (VALUES('2022-01-01'))V(x)

db<>fiddle

  • Related