November 13, 2012 at 11:53 am
Greetings:
In a stored procedure, I have a temporary table defined (#AGING_TBL) with the column AGING_BUCKET set to VARCHAR(40)
[AGING_BUCKET] VARCHAR(40),
The column (AGING_BUCKET) is primed with NULL value during the table's initial data load via a select statement. After the load, I'm updating (I was loading AGING_BUCKET during the initial load but...) the column via the CASE statement:
UPDATE #AGING_TBL
SET AGING_BUCKET =
CASE
-- DAYS AGING BUCKET #1
WHEN
GETDATE() - TRANSACTION_DATE <= DUE_DATE - TRANSACTION_DATE
THEN
' <= '
+ CONVERT(VARCHAR(20), CONVERT(NUMERIC(10,0), DUE_DATE - TRANSACTION_DATE))
+ ' Days '
-- DAYS AGING BUCKET #2
WHEN
GETDATE() - TRANSACTION_DATE > DUE_DATE - TRANSACTION_DATE
AND
GETDATE() - TRANSACTION_DATE <= (DUE_DATE - TRANSACTION_DATE) * 2
THEN etc...
During execution I yield the following error:
Msg 245, Level 16, State 1, Procedure sp_hgi_AR_Aged_Trial_Balance, Line 165
Conversion failed when converting the varchar value ' <= 30 Days ' to data type int.
I'm attempting to load ' <= 30 Days ' into a VARCHAR(40) with VARCHAR data. Why the conversion error?
Thanks in advance,
SteveP
November 13, 2012 at 1:47 pm
I've resolved this error.
The Error MSG was pointing to the first condition of the CASE Statement, the error was in the ELSE phase. By moving a parenthesis I resolved my problem.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply