Apply $__timeGroup macro but custom datetime format column

Grafana 8.3.4 on Windows. SQL Server 2012 datasource
I am trying to group a time series by interval variable. The datetime column has yyyyMMddHHmmss format.
The macro does not recognise DateTime format:

SELECT $__timeGroup( customDateTimeColumn, ${time_interval}, previous) AS time

I tried
SELECT $__timeGroup( CONVERT( DATETIME2, STUFF(STUFF(STUFF(customDateTimeColumn,13,0,':'),11,0,':'),9,0,' ')) , ${time_interval}, previous) AS time
but I get the error:

interpolation failed: error parsing interval STUFF(STUFF(STUFF(customDateTimeColumn

If I try not to use the macro:
SELECT FLOOR(DATEDIFF(second, '1970-01-01', CONVERT( DATETIME2, STUFF(STUFF(STUFF(customDateTimeColumn,13,0,':'),11,0,':'),9,0,' ')) )/${time_interval})*${time_interval) AS time
but the variable $time_interval shows as 10m, 1h, 6h... and not in seconds.

If I use $__interval, it always gets the automatic calculated interval and not the one I choose with the custom interval variable.

I tried modifying the values of the variable in the JSON model but every time I hit Save changes, it does not save them and goes back to stock.
A custom variable (key:value like 1h: 3600) won’t have the auto option.

How could I apply time grouping to this column? (It´s a read-only datasource, so I can not change the column format)

Either override the $__Interval by creating it in Variables or Make sure $interval has single quotes around the ‘1m’ or ‘10s’ etc.

Mightn’t be any help but then maybe you need to clarify the datetime column, you are missing a } in the interval*interval section

Try and build it up bit by bit checking the Generated Query below the edit option to try on database manually

Thanks for your response. $time_interval is a variable I created.
I still have the same error because it seems that you are not allowed to use sql functions with the grafana macro (it transforms before sending the query).

As my datetime column is not of Datetime type, I can not use the macro.
If I don’t use the macro, I need to parse the $time_interval variable myself in the query I guess.