Does anyone know how to create a matrix display from a database table?
I m using ASP.NET C# and the database is SQL Server 2008.
表格就这样看。
我希望矩阵像这样。
Does anyone know how to create a matrix display from a database table?
I m using ASP.NET C# and the database is SQL Server 2008.
表格就这样看。
我希望矩阵像这样。
使用TSQL pivot
create table table1
(
serverName varchar(30),
app varchar(50)
);
go
insert table1 (serverName , app) values ( server1 , app A );
insert table1 (serverName , app) values ( server2 , app A );
insert table1 (serverName , app) values ( server2 , app B );
insert table1 (serverName , app) values ( server3 , app B );
insert table1 (serverName , app) values ( server1 , app C );
insert table1 (serverName , app) values ( server3 , app C );
go
create procedure GetPivotTable
as begin
DECLARE @PivotColumnHeaders VARCHAR(MAX)
SELECT @PivotColumnHeaders =
COALESCE(@PivotColumnHeaders + ,[ + cast(t.serverName as varchar) + ] ,
[ + cast(t.serverName as varchar)+ ] )
FROM (select distinct serverName from table1) t
DECLARE @PivotTableSQL NVARCHAR(MAX)
SET @PivotTableSQL = N
select * from
(select app, serverName from table1) sourceTable
pivot
(
count(serverName) for serverName in ( + @PivotColumnHeaders + )
) pivottable
EXECUTE(@PivotTableSQL)
end
go
exec GetPivotTable
My suggestion here would be to pull the data out in exactly the format you have it, into a List of entities (at its simplest):
public class ServerApplicationRelationship
{
public string Server{get;set;}
public string Application{get;set;}
}
并形成一种习惯控制,使一个使用<代码>的超文本表格成为可能。 List<ServerApplicationRelationship> as its datasource.
从所提供的数据来看,表应十分容易。
如果你
select application,
case when exists(select 1 from example where application=ex.application and server= server 1 ) THEN 1 ELSE 0 end as [server 1],
case when exists(select 1 from example where application=ex.application and server= server 2 ) THEN 1 ELSE 0 end as [server 2],
case when exists(select 1 from example where application=ex.application and server= server 3 ) THEN 1 ELSE 0 end as [server 3]
from yourTable ex
group by application
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!