Quantcast
Channel: Active questions tagged cte - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 207

CTE Error (nvarchar to numeric)

$
0
0

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?


Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>