I am new to dynamic SQL and can't figure out what I am doing wrong here. Sorry about he alignment but i am not sure how to correct this in the forum's editor. My variables in the function are causing a conversion failure. Any ideas?
--Msg 241, Level 16, State 1, Line 7
--Conversion failed when converting date and/or time from character string.
DECLARE @FROM DATETIME
DECLARE @TO DATETIME
SET @FROM = '2014/01/01'
SET @TO = '2014/10/01'
DECLARE @SQL VARCHAR(2000)
SET @SQL = 'SELECT * FROM (SELECT
CASE
WHEN CURR_EQUIPMENT_CODE = ''_TRSP''
THEN ''TRANSPORT''
ELSE ''HIRE''
END AS Type , LINE_AMOUNT AS InvoiceAmount,DATENAME(M,INVOICE_DATE) AS INVOICEDATE