如何在变量中区分

时间:2017-08-03 07:26:53

标签: sql sql-server sql-server-2008 plsql sql-server-2012

如何在变量中区分

let mimeTypes = [
  "video/mp4", "video/3gpp", "video/quicktime"
, "video/x-ms-wmv", "video/x-msvideo", "video/mpeg"
, "video/dvd", "video/xvid", "video/x-flv"
, "video/x-f4v", "video/divx"
];

let video = document.createElement("video");

mimeTypes.forEach(type => console.log(type,  video.canPlayType(type)));

3 个答案:

答案 0 :(得分:1)

可以分三步完成

  1. 将逗号分隔值拆分为单独的行
  2. 在步骤1中应用不同
  3. 将结果连接回逗号分隔值
  4. 查询链接

    第1步:Turning a Comma Separated string into individual rows

    第2步:从上面的结果中选择Distinct

    第3步:Simulating group_concat MySQL function in Microsoft SQL Server 2005?

答案 1 :(得分:0)

答案 2 :(得分:0)

以下是使用内存表解决此问题的解决方案。

    DECLARE @var NVARCHAR(500)
    SELECT @var = 'EQUITY,EQUITY,EQUITY,EQUITY,EQUITY,EQUITY,EQUITY,DEBT,DEBT,DEBT,DEBT,DEBT,DEBT,DEBT,DEBT,DEBT,DEBT,DEBT,DEBT'

    DECLARE @tempTable TABLE (items NVARCHAR(500)) 
    DECLARE @distinctTable TABLE (items NVARCHAR(500)) 
    DECLARE @delimiter CHAR(1) = ',' --- Specify the delimiter
    DECLARE @idx INT     
    DECLARE @section NVARCHAR(500)     
    DECLARE @ouput NVARCHAR(500)

    SELECT @idx = 1     
        IF LEN(@var)<1 OR @var IS NULL  RETURN     

    WHILE @idx!= 0     
    BEGIN     
        SET @idx = CHARINDEX(@delimiter,@var)     
        IF @idx!=0     
            SET @section = LEFT(@var,@idx - 1)     
        ELSE     
            SET @section = @var    

        IF(LEN(@section)>0)
            INSERT INTO @tempTable(Items) VALUES(@section)     

        SET @var = RIGHT(@var,LEN(@var) - @idx)     
        IF LEN(@var) = 0 BREAK     
    END 

    INSERT @distinctTable (items) 
    SELECT DISTINCT * FROM @tempTable

    SET @ouput = ''
    SELECT @ouput = @ouput + items + @delimiter FROM @distinctTable
    SELECT SUBSTRING(@ouput, 0, LEN(@ouput))