jeudi 7 janvier 2016

Convert datetime to numeric

I am trying to take a date which is in a varchar column in a table, add 1 day to it, and set it as the value of a datetime variable. This is part of a process that runs daily and I need to make sure the day resets to one at the end of the month. Or at the end of the year it doesn't increase from 151231 to 151232. The problem I am having is converting @Date back to numeric in the form YYMMDD. For example VIRN_CHK = '151231', @Date as written below is 'Jan 1 2016 12:00AM'. I need to convert it to 160101 so I can save it in a column in another table of type numeric(6,0).

DECLARE @Date as datetime
set @Date = convert(varchar,dateadd(d, 1,(select top(1) VIRN_CHK from STAGE_INST)))
update cdcdatei
set OT_DATE = @Date

Aucun commentaire:

Enregistrer un commentaire