SSRS 2008 和分组列/行

发布于 2024-10-20 03:24:37 字数 4417 浏览 2 评论 0原文

矩阵... tablix...列表/矩阵...列表/tablix...我不知道。他们没有人做我希望他们做的事。

所以,我有居民数据……姓名、性别、护理级别、房间/位置信息。我有医生的电话号码。所有这些都必须看起来像我拥有的​​表单,但必须在 SSRS 中完成。

表格如下:
(电话类型和电话号码可以分开,但不必分开,如果这有意义的话。)

 _______________________________________________________________________________
| Allergies:  NKA                                                               |
|                                                                               |
|_______________________________________________________________________________|
|Resident   |    ID     |      Gender    |    Room    |  Type          Number   |
|___________|___________|________________|____________|_________________________|
|           |           |                |            |  Home          555-3242 |
|Kim        |   123     |     female     |      420   |  Cell          555-1111 |
|___________|___________|________________|____________|__Other_________234-5554_|

我需要在 SSRS 中重新创建它。我将其放在页脚中,并使用大量文本框标签、矩形等对其进行格式化,但 SSRS 在对齐和保持相同大小方面并不是那么好。我尝试过使用该布局选项,但当我部署它们时,它们有时看起来与设计和预览中的截然不同。 (有时矩形的右侧没有正确排列,或者矩形似乎并排但渲染不同并且没有重叠,但它仍然很有趣)我必须重做它,我正在尝试使用表这次在报告的末尾,这样如果信息确实占据了两行,那么它周围的所有内容都很容易增长。

我试图做的是使用矩阵中的分组来重新创建表单的整体效果,其中电话号码作为“详细信息”,并按过敏文本进行列组,然后按人员信息进行行组。但是......我似乎无法正确完成它,一切看起来都很棒,除了由于某种原因它只会在详细信息中列出一个电话号码,而我需要一个或多个电话号码才能出现。

我将数据设置为如下所示:

(name)  (ID)   (gender)   (roomNumber)   (allergies)   (phoneType)  (phoneNumber) 
Kim     123    female     410            NKA           home         555-3332
Kim     123    female     410            NKA           cell         555-2342  
Kim     123    female     410            NKA           other        555-1111           

哦......我做错了什么?如果我使用一个列表(上面的过敏文本),里面有一个表格,按 personInfo/personID/stuff 分组,并以电话号码作为详细信息,我无法将人员信息排列起来,因此这些数字不会只是挂在下面。

显然,我已经简化了数据,但这是它的总体思路......请给我一些建议。对于我的一生,我无法弄清楚分组。我需要以不同的方式排列我的数据吗?

非常感谢您的宝贵时间, Kim

Ok...编辑...我想我解释错了,因为有人说我的数据需要标准化。这就是我设置数据的方式,尝试对 personID/人员信息进行分组,然后使用电话号码作为详细信息。

所以,假设我有一个名为 person 的基表,它存储我所有的个人信息。然后我有一个名为电话号码的表,里面有我的号码。人员和电话通过 ID 关联。然后我有一个过敏表,与 personID 关联,其中有过敏 ID 和过敏文本。左外加入他们。哒哒!这是一个非常大的数据库,我必须检查大量的东西,现在实际提供查询是不可行的。抱歉......所有这些都是真正简化情况的结果,但它传达了想法,即使数据那么简单,我仍然无法完成我想要的分组(这就是我寻求帮助的内容)。

再次感谢!


我实际上确实需要这方面的帮助,今天早上我什至无法得到它......所以,让我们忘记上面的过敏部分,让它变得非常简单。我仍然无法对人员进行分组,然后使用电话号码作为详细信息。这是一些示例数据和内容......由于此报告实际上将用作表单,因此我让用户使用参数选择他们想要的人,以便将 personID 传递到我的查询/存储过程中,我只会得到一个人回来了,但作为一个例子,我在我的个人表中包含了三个人。

这不是实际的结构或数据或查询......它只是我在 10 分钟内制作的,以演示我在 SSRS 中分组时遇到的问题......所以请不要对数据库结构或类似的东西发表评论,我只是我想如果我提供一些在 SSRS 中使用的数据,我会得到更好的回应。如果我/某人可以让它处理这些数据,它将适用于我的真实数据。

create table #person
(
    personID int identity(1,1), 
    name varchar(20),
    birthdate datetime, 
    gender char(1), 
    roomnumber int

    primary key (personID) 
)

create table #phoneNumbers
(
    phoneID int identity(1,1), 
    personID int, 
    number varchar(8),
    phoneType varchar(10),

    foreign key (personID) references #person,
    primary key (phoneID) 
)

declare @scope int
declare @KimsID int

insert into #person (name, birthdate, gender, roomnumber) values ('Mike','11-22-1979','M',22)
insert into #person (name, birthdate, gender, roomnumber) values ('Kim','11-12-1985','F',123) 

set @scope = SCOPE_IDENTITY()
set @KimsID = SCOPE_IDENTITY()

insert into #phoneNumbers (personID, number, phoneType) values (@scope, '333-2323', 'Home')
insert into #phoneNumbers (personID, number, phoneType) values (@scope, '333-1111', 'Cell')
insert into #phoneNumbers (personID, number, phoneType) values (@scope, '555-6767', 'Other')


insert into #person (name, birthdate, gender, roomnumber) values ('Lizz','7-26-1984','F',4) 
set @scope = SCOPE_IDENTITY()
insert into #phoneNumbers (personID, number, phoneType) values (@scope, '444-4444', 'Home')



select  #person.personID, 
        name, 
        (datediff(YY, birthdate, getdate()) -
            case
                when((month(birthdate)*100 + day(birthdate)) >
                    (month(getdate())*100 + day(getdate()))) 
                then 1
            else 0
            end) as age,
        birthdate, 
        gender, 
        roomnumber,

        number,
        phoneType 

from    #person 
        left outer join #phoneNumbers 
        on #phoneNumbers.personID = #person.personID 

--where #person.personID = @KimsID 

order by #person.name, phoneType 

drop table #person
drop table #phoneNumbers

Matrix... tablix.... list/matrix... list/tablix... I have no idea. none of them do what I want them to do.

So, I have resident data... name, gender, care level, room/location information. And I have physician phone numbers. All of this has to look like a form I have but has to be done in SSRS.

The form looks like:
(The phone type and phone number can be divided but don't have to be, if that makes any sense.)

 _______________________________________________________________________________
| Allergies:  NKA                                                               |
|                                                                               |
|_______________________________________________________________________________|
|Resident   |    ID     |      Gender    |    Room    |  Type          Number   |
|___________|___________|________________|____________|_________________________|
|           |           |                |            |  Home          555-3242 |
|Kim        |   123     |     female     |      420   |  Cell          555-1111 |
|___________|___________|________________|____________|__Other_________234-5554_|

I need to recreate that in SSRS. I was putting it in a footer and using lots of textbox labels, rectangles and the like to format that but SSRS isn't that great about alignment and keeping things the same size. I have tried with that layout option but when I deploy them they sometimes look dramatically different that in the design and preview. (sometimes the right sides of the rectangles don't line up properly or the rectangles appear to be side by side but render differently and nothing overlaps but it still ends up funny) I have to redo it and I am trying to use a table at the end of the report this time so that if the information does happen to take up two lines, everything around it easily grows.

What I was trying to do is use grouping in a matrix to re-create the whole effect of the form with the phone numbers as the "details" and have a column group by the Allergies text and then a row group by the person info. But.... I can't seem to get it done correctly and everything looks great except for some reason it will only list one phone number in the details and I need one or more to appear.

I set up my data to look like this:

(name)  (ID)   (gender)   (roomNumber)   (allergies)   (phoneType)  (phoneNumber) 
Kim     123    female     410            NKA           home         555-3332
Kim     123    female     410            NKA           cell         555-2342  
Kim     123    female     410            NKA           other        555-1111           

Oh... what am I doing wrong? If I use a list (for the allergy text above) with a table inside, grouped by the personInfo/personID/stuff with the phone numbers as the details I can't get the person info to line up so that the numbers aren't just hanging below.

Obviously, I've simplified the data but this is the general idea of it... Please, give me some suggestions. For the life of me I can't figure out grouping. Do I need my data laid out differently?

Thank you so much............ for your time,
Kim

Ok... edit.... I guess I explained it wrong because some one said my data needs normalization. That's how I set up my data to try and use grouping on the personID/person info and then use the phone numbers as the details.

So, let's say I have a base table that's called person, that stores all my person info. Then I have a table called phone number and it has my numbers. Person and phone are associated by an ID. Then I have an allergies table, associated by the personID, it has an allergy ID, and allergy text in it. Left outer join them. Ta da! This is a really big db and I have to check tons of things and its not feasible to actually provide the query right now. Sorry... all of this is a result from really simplifying the situation but it gets the idea across and I still can't accomplish the grouping I want even if the data was that simple (which is what I am asking help with).

Thanks again!


I do actually really need help with this, I couldn't even get it this morning... So, let's forget the allergies part above to make it really easy. I still can't get the grouping to work on the Person and then use the phone numbers as the details. Here's some sample data and stuff.... Since this report is actually going to serve as form, I have the user select the person they want with the parameters so that the personID is passed into my query/stored proc and I will only get one person back but just as an example I included three people in my person table.

This not the actual structure or data or query.... its just sometime I made in 10 minutes to demonstrate the problem I am having with grouping in SSRS... so please, no comments on db structure or anything like that, I just figured I would get a better response if I provided some data to play with in SSRS. If I/some one can get it to work with this data it will work on my real data.

create table #person
(
    personID int identity(1,1), 
    name varchar(20),
    birthdate datetime, 
    gender char(1), 
    roomnumber int

    primary key (personID) 
)

create table #phoneNumbers
(
    phoneID int identity(1,1), 
    personID int, 
    number varchar(8),
    phoneType varchar(10),

    foreign key (personID) references #person,
    primary key (phoneID) 
)

declare @scope int
declare @KimsID int

insert into #person (name, birthdate, gender, roomnumber) values ('Mike','11-22-1979','M',22)
insert into #person (name, birthdate, gender, roomnumber) values ('Kim','11-12-1985','F',123) 

set @scope = SCOPE_IDENTITY()
set @KimsID = SCOPE_IDENTITY()

insert into #phoneNumbers (personID, number, phoneType) values (@scope, '333-2323', 'Home')
insert into #phoneNumbers (personID, number, phoneType) values (@scope, '333-1111', 'Cell')
insert into #phoneNumbers (personID, number, phoneType) values (@scope, '555-6767', 'Other')


insert into #person (name, birthdate, gender, roomnumber) values ('Lizz','7-26-1984','F',4) 
set @scope = SCOPE_IDENTITY()
insert into #phoneNumbers (personID, number, phoneType) values (@scope, '444-4444', 'Home')



select  #person.personID, 
        name, 
        (datediff(YY, birthdate, getdate()) -
            case
                when((month(birthdate)*100 + day(birthdate)) >
                    (month(getdate())*100 + day(getdate()))) 
                then 1
            else 0
            end) as age,
        birthdate, 
        gender, 
        roomnumber,

        number,
        phoneType 

from    #person 
        left outer join #phoneNumbers 
        on #phoneNumbers.personID = #person.personID 

--where #person.personID = @KimsID 

order by #person.name, phoneType 

drop table #person
drop table #phoneNumbers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨巷深深 2024-10-27 03:24:37

原始形式具有非规范化数据,因为一个单元格中有许多电话号码。您的数据库具有良好的标准化结构。这就是让事情变得棘手的原因。获得所需内容的最简单方法是在将数据发送到报告服务之前对数据进行非规范化。这意味着获取一个人的所有电话号码并将它们放入一个字符串中。

我拿了你的脚本,并将临时表更改为永久表。然后我添加了以下函数来获取非规范化的电话数据:

create function fnGetDenormPhoneFromPersonID(@personID int)
returns varchar(8000)
as
begin
    declare @number varchar(8);
    declare @phoneType varchar(10);

    declare @DenormPhone varchar(8000);
    set @DenormPhone = '';

    declare MyCursor cursor for
    select number, phoneType
    from phoneNumbers
    where personID = @personID;

    open MyCursor

    fetch next from MyCursor into @number, @phoneType;

    while @@FETCH_STATUS = 0
    begin
        set @DenormPhone = @DenormPhone + @phoneType + '   ' + @number + ';'
        fetch next from MyCursor into @number, @phoneType;
    end

    close MyCursor
    deallocate MyCursor

    return @DenormPhone

end

然后使用以下 select:

    select  person.personID, 
    name, 
    (datediff(YY, birthdate, getdate()) -
        case
            when((month(birthdate)*100 + day(birthdate)) >
                (month(getdate())*100 + day(getdate()))) 
            then 1
        else 0
        end) as age,
    birthdate, 
    gender, 
    roomnumber,
    dbo.fnGetDenormPhoneFromPersonID(personID) as DenormPhone

from    person 

并将其放入报表设计者构建的标准表中,所有字段都在详细信息中。

我将 Denorm Phone 的表达式更改为

=Replace(Fields!DenormPhone.Value, ";", vbCRLF)

Report Screenshot

The original form has denormalized data, as there are many phone numbers in one cell. Your database has a good normalized structure. This is what is making things tricky. The easiest way to get what you want is to denormalize the data before sending it to reporting services. This means getting all phone numbers for a person and putting them in a string.

I took your script, and changed the temporary tables to permanent tables. I then added the following function to get denormalized phone data:

create function fnGetDenormPhoneFromPersonID(@personID int)
returns varchar(8000)
as
begin
    declare @number varchar(8);
    declare @phoneType varchar(10);

    declare @DenormPhone varchar(8000);
    set @DenormPhone = '';

    declare MyCursor cursor for
    select number, phoneType
    from phoneNumbers
    where personID = @personID;

    open MyCursor

    fetch next from MyCursor into @number, @phoneType;

    while @@FETCH_STATUS = 0
    begin
        set @DenormPhone = @DenormPhone + @phoneType + '   ' + @number + ';'
        fetch next from MyCursor into @number, @phoneType;
    end

    close MyCursor
    deallocate MyCursor

    return @DenormPhone

end

Then use the following select:

    select  person.personID, 
    name, 
    (datediff(YY, birthdate, getdate()) -
        case
            when((month(birthdate)*100 + day(birthdate)) >
                (month(getdate())*100 + day(getdate()))) 
            then 1
        else 0
        end) as age,
    birthdate, 
    gender, 
    roomnumber,
    dbo.fnGetDenormPhoneFromPersonID(personID) as DenormPhone

from    person 

and put it into a standard table built by the report designer, with all fields in the details.

I changed the expression for Denorm Phone to

=Replace(Fields!DenormPhone.Value, ";", vbCRLF)

Report Screenshot

辞取 2024-10-27 03:24:37

在 SSRS 2005 中,矩阵、列表和表格都是不同的东西。 2008 年,他们将它们合并为 tablix。您仍然拥有所有三个控件,但它们下面都是具有不同默认值的 tablix。

看起来您想使用 3 级矩阵。

  1. 过敏
  2. ID,然后包括房间、性别和居民的额外列。
  3. 详细信息 - 并不是真正的组,因为它不会对任何内容进行分组,只是为了显示剩余的行。

In SSRS 2005, Matrixes and Lists and Tables were all different things. In 2008 they merged them into a tablix. You still have all three controls but underneath they are all a tablix with different defaults.

It looks like you want to use a matrix with 3 levels.

  1. Allergies
  2. ID and then include the extra columns for room, gender and resident.
  3. Details - Not really a group as it doesn't group on anything just for showing the remaining rows.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文