第一表的[index]与第二表的哪个字段关联?
解决方案 »
- 统计sql,谢谢。。
- 什么是ROWGUID 列,有什么用
- 写存贮过程时,定义变量是随用随声明好呀,还是在前面将所有变量声明放在一起.哪种规范,方便呢?
- SQL中三个数比较大小
- SQL SERVER计划执行失败,而手工执行却成功
- shinesky(找天的人) talantlee(風) 各50分
- 我可以一次给我的数据库的所有表设置权限吗?
- 这样的表怎样设计好?
- 1. 能不能让能打开win2000 server并运行sql server2000的用户也不能查看某些数据表。
- 哪位过来人能给小弟指点迷津,因为微软这样说...
- 关于SQLSERVER 发布,订阅的问题
- SQL数据库语句查询的问题,请高手帮忙!
ID对应的是存储过程的ID,(外键对应的是存储过程主信息表的ID)
index 对应的是参数的序号,
param 参数的名字
badvalue 错误的参数值
badtype 错误值的类型
badreturnvalue 错误的返回值ID index param badvalue badtype badreturnvalue
1 1 @Accounts 45645 1 1
1 2 @Pwd 456 2 1
1 3 @LoginIP 1131 1 1
1 4 @OutPutValue 8978 3 2
2 1 @Accounts 4656 4 4
3 1 @UserId 45645 5 2
11 1 @UserID 456456 4 4
12 1 @ServerID 45645 8 8
13 1 @ServerID 456456 9 7另外一张存储过程主信息表ID:存储过程的ID,
name: 存储过程的名字,
backtype:返回值类型
rightvalue:返回值预期的正确值,
ID name backtype rightvalue
1 UP_UserInfo_Login 1 0
2 UP_UI_ID_OneUserInfo_S 2 1
3 UP_MIf_DoorTicket_S 2 2
4 UP_TGt_HavePrizeLayout_S 2 9
5 UP_TGt_ZorePrizeLayout_S 2 4
6 UP_SSt_ServerList_S 2 1
7 UP_TGt_ZorePrizeRunTerm_S 2 4
8 UP_TGt_HavePrizeRunTerm_S 2 9
9 UP_TGt_HallSeverList_S 2 1
10 UP_DDo_List_S 2 16
11 UP_UIf_UID_Coin_S 2 1
12 UP_SSt_ID_S 2 1
13 UP_SSt_ID_Port_S 2 1
转换成:
param2 param3,param4 ...paramN 与param1相同 有对应错误的参数值,对应的返回值类型,对应返回值预期的正确值....表示省略ID rightvalue param1 badvalue1 badtype1 badreturnvalue1 param2 .... param3 .... param4 ....
1 0 @Accounts 45645 1 1 @Pwd @LoginIP @OutPutValue
2 1 @Accounts .... .... ....
3 2 @UserId .... .... ....
11 1 @UserID .... .... ....
12 1 @ServerID .... .... ....
13 1 @ServerID .... .... ....存储过程ID和它的所有参数 信息第一表的[index]与第二表的字段关联,
只通过ID关联,
-- Author:Flystone
-- Version:V1.001 Date:2008-05-15 初稿
-- Version:V1.002 Date:2008-05-16 1、 处理空格带来的异常
-- 2、 增加了形如yyyy-mm-dd hh:mm:ss
-- yyyy-m-d h:m:s 格式的处理
*/-- Test Data: Ta
If object_id('Ta') is not null
Drop table Ta
Go
Create table Ta(ID int,[index] int,param varchar(20),badvalue int,badtype int,badreturnvalue int)
Go
Insert into Ta
select 1,1,'@Accounts',45645,1,1 union all
select 1,2,'@Pwd',456,2,1 union all
select 1,3,'@LoginIP',1131,1,1 union all
select 1,4,'@OutPutValue',8978,3,2 union all
select 2,1,'@Accounts',4656,4,4 union all
select 3,1,'@UserId',45645,5,2 union all
select 11,1,'@UserID',456456,4,4 union all
select 12,1,'@ServerID',45645,8,8 union all
select 13,1,'@ServerID',456456,9,7
Go
--Start
declare @sql varchar(8000)
--set @sql = ''
select @sql=isnull(@sql+',','')+'max(case when [index]='+ltrim([index])+' then param end) [param'+ltrim([index])+']
'+
',max(case when [index]='+ltrim([index])+' then badvalue end) [badvalue'+ltrim([index])+']
'+
',max(case when [index]='+ltrim([index])+' then badtype end) [badtype'+ltrim([index])+']
'+
',max(case when [index]='+ltrim([index])+' then badreturnvalue end) [badreturnvalue'+ltrim([index])+']
'
from ta group by [index]
exec('select id,'+ @sql + ' from ta group by id')
--Result:
/*
id param1 badvalue1 badtype1 badreturnvalue1 param2 badvalue2 badtype2 badreturnvalue2 param3 badvalue3 badtype3 badreturnvalue3 param4 badvalue4 badtype4 badreturnvalue4
----------- -------------------- ----------- ----------- --------------- -------------------- ----------- ----------- --------------- -------------------- ----------- ----------- --------------- -------------------- ----------- ----------- ---------------
1 @Accounts 45645 1 1 @Pwd 456 2 1 @LoginIP 1131 1 1 @OutPutValue 8978 3 2
2 @Accounts 4656 4 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
3 @UserId 45645 5 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
11 @UserID 456456 4 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
12 @ServerID 45645 8 8 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
13 @ServerID 456456 9 7 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL警告: 聚合或其它 SET 操作消除了空值。*/
--End
-- Author:Flystone
-- Version:V1.001 Date:2008-05-15 初稿
-- Version:V1.002 Date:2008-05-16 1、 处理空格带来的异常
-- 2、 增加了形如yyyy-mm-dd hh:mm:ss
-- yyyy-m-d h:m:s 格式的处理
*/-- Test Data: Ta
If object_id('Ta') is not null
Drop table Ta
Go
Create table Ta(ID int,[index] int,param varchar(20),badvalue int,badtype int,badreturnvalue int)
Go
Insert into Ta
select 1,1,'@Accounts',45645,1,1 union all
select 1,2,'@Pwd',456,2,1 union all
select 1,3,'@LoginIP',1131,1,1 union all
select 1,4,'@OutPutValue',8978,3,2 union all
select 2,1,'@Accounts',4656,4,4 union all
select 3,1,'@UserId',45645,5,2 union all
select 11,1,'@UserID',456456,4,4 union all
select 12,1,'@ServerID',45645,8,8 union all
select 13,1,'@ServerID',456456,9,7
Go
-- Test Data: pro
If object_id('pro') is not null
Drop table pro
Go
Create table pro(ID int,name varchar(40),backtype int,rightvalue int)
Go
Insert into pro
select 1,'UP_UserInfo_Login',2,1 union all
select 2,'UP_UI_ID_OneUserInfo_S',2,2 union all
select 3,'UP_MIf_DoorTicket_S',2,2 union all
select 4,'UP_TGt_HavePrizeLayout_S',2,9 union all
select 5,'UP_TGt_ZorePrizeLayout_S',2,4 union all
select 6,'UP_SSt_ServerList_S',2,1 union all
select 7,'UP_TGt_ZorePrizeRunTerm_S',2,4 union all
select 8,'UP_TGt_HavePrizeRunTerm_S',2,9 union all
select 9,'UP_TGt_HallSeverList_S',2,1 union all
select 10,'UP_DDo_List_S',2,16 union all
select 11,'UP_UIf_UID_Coin_S',2,1 union all
select 12,'UP_SSt_ID_S',2,1 union all
select 13,'UP_SSt_ID_Port_S',2,1
Go
--Start
declare @sql varchar(8000)
--set @sql = ''
select @sql=isnull(@sql+',','')+'max(case when [index]='+ltrim([index])+' then param end) [param'+ltrim([index])+']
'+
',max(case when [index]='+ltrim([index])+' then badvalue end) [badvalue'+ltrim([index])+']
'+
',max(case when [index]='+ltrim([index])+' then badtype end) [badtype'+ltrim([index])+']
'+
',max(case when [index]='+ltrim([index])+' then badreturnvalue end) [badreturnvalue'+ltrim([index])+']
'
from ta group by [index]
exec('select a.id,rightvalue,'+ @sql + ' from ta a,pro b where a.id = b.id group by a.id,b.rightvalue')
--Result:
/*
id rightvalue param1 badvalue1 badtype1 badreturnvalue1 param2 badvalue2 badtype2 badreturnvalue2 param3 badvalue3 badtype3 badreturnvalue3 param4 badvalue4 badtype4 badreturnvalue4
----------- ----------- -------------------- ----------- ----------- --------------- -------------------- ----------- ----------- --------------- -------------------- ----------- ----------- --------------- -------------------- ----------- ----------- ---------------
1 1 @Accounts 45645 1 1 @Pwd 456 2 1 @LoginIP 1131 1 1 @OutPutValue 8978 3 2
11 1 @UserID 456456 4 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
12 1 @ServerID 45645 8 8 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
13 1 @ServerID 456456 9 7 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
2 2 @Accounts 4656 4 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
3 2 @UserId 45645 5 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL警告: 聚合或其它 SET 操作消除了空值。*/
--End