Selecting Distinct Years from Data

Selecting Distinct Years from Data

Hi All,

I am trying to do something that I've done a million times in SQL Server Studio, but for some reason I can't get it to work in Outsystems.

I have a table that has a bunch of data, including a date field.  What I want, is to select only the Distinct Years in that data to use in a Combo Box.

I have tried a million queries, but the one I think should work is this:

However, I get the following error, even when I add a column alias (ie. "sample_date AS year":

Any help would be greatly appreciated.  Thank you!

Matt Yeager
Nevermind.  I figured it out.  I don't know why I didn't use "Unique" before. 

The proper query was:

SELECT UNIQUE TO_CHAR({t_sm_grape_data_master}.[sample_date], 'YYYY') FROM {t_sm_grape_data_master}

Thanks anyways!

The problem you had on the first screenshot was actually because the "Year" function does not exist in Oracle. (It actually shows in pink on the advanced sql editor but is only valid in MS SQL)

Another alternative to the TO_CHAR would be the "Extract".

SELECT DISTINCT EXTRACT(YEAR FROM {t_sm_grape_data_master}.[sample_date])
FROM {t_sm_grape_data_master}

João Rosado