We work with multiple tables that contain a date field, sometimes we need to separate the date string into 3 columns (day / month / year). I have done a function where you pass the date string and it returns those 3 columns, but how do I return them inside another Query?
example:
select *, separadata(REP_DATA_INICIO) from intranet_reportmensal
The function would apply to each line of this query.
The function is this
FUNCTION [dbo].[separadata](@data varchar(10))
returns TABLE
AS RETURN SELECT Parsename(Replace(@data, '/', '.'), 3) as DIA, Parsename(Replace(@data, '/', '.'), 2) as MES, Parsename(Replace(@data, '/', '.'), 1) as ANO