ssrs表达式每2个字符分割一次字符串

时间:2017-08-16 02:08:09

标签: reporting-services split ssrs-2008

  1. 我正在使用SSRS执行以下功能

    I have a string stractual= 7700964455 
    
    I need to split the above string for every 2 characters something like below
    
  2. 77 00 96 44 55

    Also I have another string value strexist = "99"
    
    I need to verify whether strexist exists in stractual to meet the condition.
    
    
    77
    00
    96
    44
    55
    

3 个答案:

答案 0 :(得分:0)

执行字符串拆分的非常基本的SQL Server函数看起来像这样:

CREATE FUNCTION dbo.SPACEIT (@str nvarchar (255)) RETURNS nvarchar (500)
AS
BEGIN
    DECLARE @cnt int = 1;
    DECLARE @result nvarchar (500) = ''

    WHILE @cnt <= LEN(@str)
    BEGIN
      SET @result = @result + SUBSTRING(@str,@cnt,1)
      if (@cnt % 2 = 0)
          set @result = @result + ' '
      SET @cnt = @cnt + 1
    END 

    return @result
END

答案 1 :(得分:0)

要控制上述SSRS级别的功能,我们可以编写vb脚本,如下所示

enter image description here

单击报告属性并转到“代码”选项卡并编写vb函数

enter image description here

你可以在下面写下自己的逻辑

enter image description here

要访问您需要在表达式

中编写如下内容的函数
=Code.SubjectDetailsCheck("Value","1")

enter image description here

答案 2 :(得分:0)

您可以使用以下查询作为技巧 -

DECLARE @VAR VARCHAR(10)='702030405'
DECLARE @RNG INT=LEN(@VAR)
SELECT @RNG
SELECT TOP (@RNG) ROW_NUMBER() OVER(ORDER BY A.OBJECT_ID) R
INTO #TEMP  
FROM SYS.all_objects A
CROSS JOIN SYS.all_objects B

SELECT * , ROW_NUMBER() OVER(ORDER BY R DESC) as R1 INTO #T1
FROM #TEMP


--DECLARE @VAR VARCHAR(10)='7020304056'

Select CASE WHEN LEN(SUBSTRING(@VAR,R,len(@VAR)-R))>2 
THEN LEFT(SUBSTRING(@VAR,R,len(@VAR)-R),2)
ELSE SUBSTRING(@VAR,R,len(@VAR)-R) END SS
, ROW_NUMBER() OVER(ORDER BY R)R2
INTO #T3
FROM #T1

SELECT * FROM #T3
WHERE NOT(R2% 2=0)

DROP TABLE #TEMP
DROP TABLE #T1
DROP TABLE #T3