sql server - Date conversion error in SQL on one Computer, but the code works on another? -
i have piece of code
select * [db].[dbo].[stg_table] convert(datetime, cast([change_date] char(8))) > dateadd(day, -3, getdate())
the change_date of type numeric(8,0).
i have used code before. still works on local machine on same data, when run on development server, gives error:
conversion failed when converting date and/or time character string.
both computers has same system date settings in control panel.
if remove convert, so:
select * [db].[dbo].[stg_table] cast([change_date] char(8)) > dateadd(day, -3, getdate())
it gives same error leads me believe after greater than, still don't know why.
try convert.
select * [db].[dbo].[stg_table] [change_date] > cast(convert(char(8),dateadd(day, -3, getdate()),112) numeric(8,0))
getdate() -> char(8) -> numeric , compare table field
Comments
Post a Comment