快捷搜索:

sqlserver2005 行列转换实现方法

复制代码 代码如下:

--Create Company Table
Create Table Company
(
ComID varchar(50) primary key,
ComName nvarchar(50) not null,
ComNumber varchar(50) not null,
ComAddress nvarchar(200),
ComTele varchar(50)
)
--Create Product Table
Create Table Product
(
ProductID varchar(50) primary key,
ComID varchar(50) not null,
ProName nvarchar(200) not null,
ProNumber int not null
)
select * from product
--insert into table value
insert Company select('58C0F3FD-7B98-4E74-A1A8-7B144FCB8707','CompanyOne','SH19991028','ShangHai','98765432112')
union all select('768B2E84-0AAB-4653-8F5B-5EF6165204DB','CompanyTwo','SH19991028','ShangHai','98765432113')
union all select('AAE86C36-C82B-421D-BC55-E72368B1DE00','CompanyThree','SH19991028','ShangHai','98765432114')
union all select('C672B359-C800-47DE-9BB4-6D0FC614594C','CompanyFour','SH19991028','ShangHai','98765432115')
union all select('FDBA8B3F-1851-4B73-9A20-A24AEF721AAE','CompanyFive','SH19991028','ShangHai','98765432116')
insert Product sleect('1598A60B-FCFD-4269-864B-CB999E8EA5CA','AAE86C36-C82B-421D-BC55-E72368B1DE00','SqlServer2005',500)
union all select('19D7BF2F-79FD-414E-B648-F105D4AB1EBB'    ,'AAE86C36-C82B-421D-BC55-E72368B1DE00',    'Office',    400)
union all select('232B6109-C575-4316-A9BD-0C58F737BE7B'    ,'FDBA8B3F-1851-4B73-9A20-A24AEF721AAE',    'SqlServer2005'    ,200)
union all select('4F30E12C-7654-40CC-8245-DF1C3453FBC5'    ,'768B2E84-0AAB-4653-8F5B-5EF6165204DB',    'Office',    400)
union all select('54C6E4C2-1588-43DF-B22C-0697A1E27DB0'    ,'58C0F3FD-7B98-4E74-A1A8-7B144FCB8707',    'Office',    400)
union all select('551EB6CA-3619-4250-98A0-7231BB4C3D58'    ,'FDBA8B3F-1851-4B73-9A20-A24AEF721AAE',    'SqlServer2000',    100)
union all select('5BAD331C-B6E4-440E-AC54-52CE13166843'    ,'768B2E84-0AAB-4653-8F5B-5EF6165204DB',    'SqlServer2005',    1000)
union all select('5C039C53-2EE4-4D90-BA78-7A20CEC4935C'    ,'58C0F3FD-7B98-4E74-A1A8-7B144FCB8707',    'Windows2000',    200)
union all select('673A8683-CD03-40D2-9DB1-1ADA812016E2'    ,'58C0F3FD-7B98-4E74-A1A8-7B144FCB8707',    'WindowsXP',    100)
union all select('6B9F771B-46EA-4496-B1DA-F10CB53F6F62'    ,'C672B359-C800-47DE-9BB4-6D0FC614594C',    'WindowsXP',    100)
union all select('770089B1-A80A-4F48-8537-E15BD00A99E7'    ,'AAE86C36-C82B-421D-BC55-E72368B1DE00',    'WindowsXP',    100)

您可能还会对下面的文章感兴趣: