我有两个名为A和B的数据集.A有一个名为Paper的字段。 B有两个名为Subject和Grade的字段。
这些字段中的数据类似于:
+---------+-------+ +-----------------------------+
| Subject | Grade | | Paper |
+---------+-------+ +-----------------------------+
| English | A | | English Literature Autumn 1 |
| Maths | D | | Further Maths Spring 2 |
| Physics | F | | Physics |
+---------+-------+ +-----------------------------+
我通常使用的LookupSet如下:
=LookupSet(Fields!Paper.Value, Fields!Subject.Value, Fields!Grade.Value, "B")
但当然它只返回 F ,因为物理是唯一相同的字段。我需要能够回归其他成绩的东西。我试过了:
=LookupSet(Fields!Paper.Value, Fields!Subject.Value.IndexOf(Fields!Subject.Value) >= 0, Fields!Grade.Value, "B")
或者
=LookupSet(Fields!Paper.Value, Fields!Subject.Paper.ToLowerInvariant().Contains(Fields!Subject.Value), Fields!Grade.Value, "B")
有没有办法在不改变数据的情况下实现它?
答案 0 :(得分:1)
如果源是SQL Server,则可以使用LIKE在T-SQL中执行此操作。
WITH
subject_grades
AS
(
SELECT tbl.* FROM (VALUES
( 'English', 'A')
, ( 'Maths', 'D')
, ( 'Physics', 'F')
) tbl ([Subject], [Grade])
)
,
subject_papers
AS
(
SELECT tbl.* FROM (VALUES
( 'English Literature Autumn 1')
, ( 'Further Maths Spring 2')
, ( 'Physics')
) tbl ([Paper])
)
SELECT
sp.Paper
, sg.Grade
FROM
subject_papers AS sp
LEFT JOIN subject_grades AS sg ON sp.[Paper] LIKE '%' + sg.[Subject] + '%'