DERIVED Column statement for date

San 121 Reputation points
2021-01-05T07:18:36.65+00:00

Hi Experts,

I want to generate a derived column if date is null then lastyear else thisyear

here is the statement
IF (DATE)==" ":YEAR(DATE_LY)):(YEAR(DATE)

SQL Server Integration Services
0 comments No comments
{count} votes

Answer accepted by question author
  1. Monalv-MSFT 5,926 Reputation points
    2021-01-05T08:24:17.787+00:00

    Hi @San ,

    1.We can use the following expression in Derived Column:
    Date == " " ? YEAR((DT_DATE)Date) - 1 : YEAR((DT_DATE)Date)

    2.We should add error redirect after Derived Column.

    Please refer to the following pictures:
    53479-df.png
    53420-ffsou.png
    53537-dec1.png
    53583-dec1output.png
    53517-dec2.png
    53520-dec2output.png
    53591-unionalloutput.png

    Best Regards,
    Mona


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues in November--What can I do if my transaction log is full?
    Hot issues in November--How to convert Profiler trace into a SQL Server table?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.