-8
    (to_char(sysdate,'YYYY')+least(sign((sysdate-to_date('01-Aug-'||
to_char(sysdate,'YYYY'),'DD-Mon-RRRR'))),0)) "AcYear"

Error:

'to_char' is not a recognized built-in function name.

I tried changing to_char and to_date to CONVERT but getting error.

I am expecting to see 2016 as AcYear

Can someone please help?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Aruna Raghunam
  • 903
  • 7
  • 22
  • 43
  • 7
    Are you sure you are using sql server? `to_char` isn't a function in sql server. – ollie May 19 '17 at 13:23
  • 5
    Oracle is not SQL Server: functions vary. – xQbert May 19 '17 at 13:24
  • 5
    What about the message do you not understand? Why are you using an Oracle/Postgres/Teradata function in SQL Server? At the very least, you should edit your question and provide sample data and desired results. – Gordon Linoff May 19 '17 at 13:24

1 Answers1

5

In SQL Server if you want the first day of August, then use datefromparts():

select datefromparts(year(getdate()), 8, 1)

This works in SQL Server 2012+. Earlier versions require slightly more work:

select cast(datename(year, getdate()) + '0801' as date)
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786