I am basically trying to store the output of the query in a variable but getting the error message
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
--DECLARE @companystring varchar(max)= '867343,867358,867443,867458,867543'
    DECLARE @companystring varchar(max)
    set @companystring = (SELECT DISTINCT Top 1000(mc.companyId) FROM ciqMarketCap mc 
    JOIN ciqCompany c   ON c.companyid = mc.companyid
    WHERE c.companyStatusTypeId NOT IN (5,6) AND  c.companyTypeId IN (1,4))
    select 
            ci.id
        into #companyId
        from dbo.splitstring(@companystring) ci
Could somebody tell me what the problem is ?
 
     
    