Oracle to SQL Server: Month + Year where clause -
i have oracle query goes follow:
select ... ... ... , to_char(a.bill_date, 'mmyyyy') = '072017' ... order ...
in sql server, have month() , year() functions.
select ... ... ... , month(a.bill_date) = month(getdate()) , year(a.bill_date) = year(getdate()) ... order ...
is there allows me apply month-year constraint oracle to_char through single step? have make parameterized , maintain compatibility both databases through common interface. now, 1 require 2 parameters , other one.
i think closest thing oracle's to_char
function in sql server convert
. convert
see no option request year , month. rather, need accept @ least day well, , possibly timestamp in addition this.
convert
accepts date format mask parameter third argument. 112
mask returns date in following format:
yyyymmdd
so date in question return this:
201707dd
where have left dd
undefined don't know day given record might have. can close want taking left 6 characters of output, e.g.
where ... , left(convert(varchar, a.bill_date, 112), 6) = '201707'
Comments
Post a Comment