zoukankan      html  css  js  c++  java
  • Dynamics 365 V9.0版本后引入多选项集,SQL查询时,如何显示选中的选项名称

    SQL查询语句如下:

    select new_name,new_code,new_multipleselection,multipleselection.name 
    from new_attachment
    outer apply fn_GetPickListNameByMultiple('new_attachment','new_multipleselection',new_multipleselection,1033)  multipleselection

    查询结果如下图:

     

    下面是对应的SP,直接在我们数据库执行后,sql就可以直接使用功能:

    USE [***_MSCRM]
    GO
     
    SET ANSI_NULLS ON
    GO
     
    SET QUOTED_IDENTIFIER ON
    GO
     
    CREATE FUNCTION [dbo].[fn_GetPickListNameByMultiple] 
    (
      @entityName NVARCHAR(200)
    , @fieldName NVARCHAR(200)
    , @fieldValue NVARCHAR(200)
    , @langId int
    )
    RETURNS @MultiTable TABLE 
    (
    [name] nvarchar(max)
    )
    AS
    begin
    DECLARE @CurrentIndex int;
         DECLARE @NextIndex int;
         SELECT @CurrentIndex=1;
    DECLARE @Text nvarchar(max);
    DECLARE @ReturnText nvarchar(max)
    DECLARE @value nvarchar(max)
    set @ReturnText='';
    set @value='';
    set @fieldValue=replace(replace(@fieldValue,'[',''),']','')
    WHILE(@CurrentIndex<=len(@fieldValue))
             BEGIN
                 SELECT @NextIndex=charindex(',',@fieldValue,@CurrentIndex);
                 IF(@NextIndex=0 OR @NextIndex IS NULL)
                     SELECT @NextIndex=len(@fieldValue)+1;
                     SELECT @Text=substring(@fieldValue,@CurrentIndex,@NextIndex-@CurrentIndex);
    if(@Text<>-1)
    begin
    SELECT DISTINCT 
     @value=sm.value
    FROM   entity e
    INNER JOIN stringmap sm
    ON e.objecttypecode = sm.objecttypecode AND
      sm.attributename = @fieldName AND sm.AttributeValue = @Text
      AND sm.LangId=@langId
    WHERE  e.OverwriteTime=0 AND e.Name = @entityName
    set @ReturnText=@ReturnText+@value+',';
    end
                     SELECT @CurrentIndex=@NextIndex+1;
                 END
    if(isnull(@fieldValue,'')='')
    begin
    INSERT INTO @MultiTable([name]) VALUES(null)
    end
    else
    begin
    INSERT INTO @MultiTable([name]) VALUES(substring(@ReturnText,1,len(@ReturnText)-1))
    end
    RETURN 
    end
    GO
  • 相关阅读:
    short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错?
    SpringMVC常用的注解有哪些?
    Spring支持的ORM?
    什么是代理?
    一对一、一对多的关联查询 ?
    iHTML 的 form 提交之前如何验证数值文本框的内容全部为数字?
    解释JDBC抽象和DAO模块?
    Bean 工厂和 Application contexts 有什么区别?
    GitHub的注册
    HTML的学习
  • 原文地址:https://www.cnblogs.com/parkerchen/p/13388661.html
Copyright © 2011-2022 走看看