how to convert the output of sub query into numeric

Published on Author Code Father
How to convert the output of sub query into numeric?

It’s a little hard to tell without the concrete table definitions, but I’m pretty sure you’re trying to compare different data types to each other. If this is the case you can make use of the CAST or the CONVERT function, for example:

SELECT 
    [rptName]
FROM [RptTable]
WHERE [rpt_id] IN
                 (
                  SELECT 
                      CONVERT(int, LEFT([Reports], NULLIF(LEN([Reports]) - 1, -1)))
                  FROM [repoAccess1]
                  WHERE [uid] = 'VIKRAM')
                 

UPDATE: Since you have updated your question: The LEFT function returns results of either varchar or nvarchar data type. So the resulting query would be

SELECT 
    [rptName]
FROM [RptTable]
WHERE [rpt_id] IN('1', '2')

Please note the apostrophes (is this the correct term?) around the values. Since [rpt_id] seems to be of data type int the values cannot implicitly be converted. And that’s where the aforementioned CAST or CONVERT come into play.

Comments

comments