ssrs expression to split string possible?

2019-01-26 14:42发布

问题:

so in my query i have select columnx from tblz

it returns 001.255556.84546

I want to be able to split this via '.' and put it into three columns.

column1 = 001
column2 = 255556
column3 = 84576

is this possible?

回答1:

Create three calculated fields with the following expressions:

=(Split(Fields!columnx.Value, ".")).GetValue(0)
=(Split(Fields!columnx.Value, ".")).GetValue(1)
=(Split(Fields!columnx.Value, ".")).GetValue(2)

I'm not sure it works or not, maybe give it a try. You might need to use IIF() statement to check values before getting them.



回答2:

For info, in 2008 these dont work, you have to do the following:

=Split(Fields!returnedValue.Value, ".").GetValue(0)


回答3:

In SSRS you reference the field name, tell it the delimiter to use. Since you are not assigning to a variable, per se, you then need to tell it which part of the split string to use. In your example

=Split(Fields!returnedValue.Value,".")(0)
=Split(Fields!returnedValue.Value,".")(1)
=Split(Fields!returnedValue.Value,".")(2)

You would replace returnedValue with whatever the actual field name is, and place each one of those into your columns 1 - 3, respectively.



回答4:

This answer was originally posted in the question instead of being posted as an answer:

=(Split(Fields!columnx.Value,".")).GetValue(0)
=(Split(Fields!columnx.Value,".")).GetValue(1)
=(Split(Fields!columnx.Value,".")).GetValue(2)