I'm using a CTE to convert SSRS stored proc's into BO stored proc's, as apparently I can't use temp tables with Business Objects.
I'm having this query:
;WITH cte1AS( SELECT cv.issue , cv.customfield , CAST(STRINGVALUE AS NUMERIC) AS priority_num --INTO #temp_priority_val FROM proddb1.customfieldvalue cv WITH (NOLOCK) INNER JOIN proddb1.customfield e WITH (NOLOCK) ON cv.CUSTOMFIELD = e.id AND e.cfname = 'Issue Priority') ,cte2AS( SELECT a.ISSUE , f.customvalue priority_num --INTO #temp_priority FROM cte1 a INNER JOIN proddb1.customfieldoption f WITH (NOLOCK) ON a.CUSTOMFIELD = f.CUSTOMFIELD AND CAST(a.priority_num AS NUMERIC) = f.id) SELECT * FROM cte2
I keep getting an Error converting data type nvarchar to numeric.
error on this execution. The priority_num
column is an nvarchar column that is CAST in the first CTE. When I execute this within the original statement that had the temp tables it works perfectly fine. It must be something with the CTE scope?