Ok I am writing an archive process in SQL 2000 for an application. Long story short I need to grab values that are equal to or less than a date. The script does not work as created
SELECT 0, po_number FROM AAD..t_receipt WHERE receipt_date <= 1/1/2013
But if I put quotes around the date date at the end I do get the expected results
SAMPLE OF MODIFIED SCRIPT
SELECT 0, po_number FROM AAD..t_receipt WHERE receipt_date <= '1/1/2013'
Below is the code that I am playing with. I need to get quotes around the date set. I have attempted that below but get an error.
ERROR WHEN ATTEMPTING TO ENCLOSE DATE IN SINGLE QUOTE:
Msg 403, Level 16, State 1, Procedure GenerateArchiveScipts, Line 242
Invalid operator for data type. Operator equals divide, type equals varchar.
Can someone please help? This is the last leg of this project and for the life of me I can't get past this final step. God I hate dealing with dates in SQL 2000.
SET @SQLsource = 'SELECT '
+ CAST(@ArchiveBatchID AS varchar) + ', '+ @ArchiveControlField + ' FROM ' + 'AAD..' + @TableName + ' WHERE ' + @ArchiveSourceDateField + ' <= '''' + cast(datepart(mm, @ArchiveCutOffDate) as varchar) + '/' + cast(datepart(dd, @ArchiveCutOffDate) as varchar) + '/' + cast(datepart(yyyy, @ArchiveCutOffDate) as varchar) + '''
<hr noshade size='1' width='250' color='#BBC8E5'>