日期:2014-05-17 浏览次数:20710 次
ALTER proc [dbo].[text]
@ModelID int,
@TableID int
as
begin
declare c1 cursor for select ModelFieldID from ModelInfo where ModelID=@ModelID
while @@FETCH_STATUS=0
begin
open c1
declare @ModelFieldID int
fetch next from c1 into @ModelFieldID
declare c2 cursor for select ModelFieldName from ModelFieldInfo where ModelFieldID=@ModelFieldID
while @@FETCH_STATUS=0
begin
open c2
declare @ModelFieldName varchar(100)
fetch next from c2 into @ModelFieldName
declare @sql varchar(6000)
set @sql='(select FieldContext'
select @sql=@sql+'from FieldInfo where FieldTime=a.FieldTime and ModelFieldID'+@ModelFieldID+')'as @ModelFieldName
from (select distinct FieldTime from FieldInfo where TableID=@TableID) a
exec(@sql)
end
end
close c2
deallocate c2
end
close c1
deallocate c1
ALTER proc [dbo].[text]
@ModelID int,
@TableID int
as
begin
declare @ModelFieldID int,@ModelFieldName nvarchar(100)
declare @sql nvarchar(4000),@tb nvarchar(100)
declare c1 cursor for
select a.ModelFieldID,b.ModelFieldName from ModelInfo a
inner join ModelFieldInfo b on a.ModelFieldID=b.ModelFieldID
where a.ModelID=@ModelID
open c1
fetch next from c1 into @ModelFieldID,@ModelFieldName
while @@fetch_status=0
begin
set @sql='select (select FieldContext '
set @sql=@sql+'from FieldInfo where FieldTime=a.FieldTime and ModelFieldID='
+cast(@ModelFieldID as varchar)+') as '+ @ModelFieldName
select @tb=FieldTime from FieldInfo where TableID=@TableID
set @sql=@sql+' from '+@tb+' as a'
exec(@sql)
fetch next from c1 into @ModelFieldID,@ModelFieldName
end
close c1
deallocate c1
end