sql server - how to cast or convert numeric/varchar to date data type field in sql and use in update statement? -
good day!
i have 2 questions how update date data type column field using varchar , numeric column field
1.)mydate
varchar(8)--> varchar
column field
select mydate mytable
result: 20141120
my question how can update date column field using varchar column field using cast or convert
update table2 set date = (select mydate mytable)
which error!!! , i'm stuck.
2.)mydate
numeric(8) --> numeric column
field
select mydate mytable
result:
20101015
20140910
etc.......
update table2 set date = (select mydate mytable a, mytable2 b a.id=b.id)
my question how can update date column field using numeric column field using cast or convert
i used different cast , convert still i'm getting error!
what correct syntax this?
thank your help!
to convert string date field need use convert function:
convert(datetime, mydate, 101)
this expecting string field, if mydate field numeric field need cast string, convert command like:
convert(datetime, cast(mydate varchar), 101)
the third parameter of function determined format of date in previous parameter, can find full list on msdn @ http://msdn.microsoft.com/en-us/library/ms187928.aspx
Comments
Post a Comment