I'm trying to pull together two databases in a view that will show invoicing from both systems.
One table lists invoices by date (ie January's sales are any invoice with a January date), the other table lists invoices by year and period (so, January's sales are '2017' period '7' - irrespective of date). As the second system allows invoices to be posted within a period that is from outside that periods date range, I'm trying to create a date field from the year/period fields using a case statement in order to show the same Invoiced sales as the system does.
LedgerYear +
case
when LedgerPeriod = 4 then '-10-01'
when LedgerPeriod = 5 then '-11-01'
when LedgerPeriod = 6 then '-12-01'
when LedgerPeriod = 7 then '-01-01'
when LedgerPeriod = 8 then '-02-01'
when LedgerPeriod = 9 then '-03-01'
when LedgerPeriod = 10 then '-04-01'
when LedgerPeriod = 11 then '-05-01'
when LedgerPeriod = 12 then '-06-01'
when LedgerPeriod = 1 then '-07-01'
when LedgerPeriod = 2 then '-08-01'
when LedgerPeriod = 3 then '-09-01'
end
as 'InvDate',
I'm getting the following..
Error converting data type varchar to numeric.
Presumably, the LedgerYear is numeric and the '-10-01' etc are varchars. The InvDate in the other table in the union is in 'datetime' format.
How can I get the output of the case statement to be in datetime format?