/*
顯示指定表
對於表中主鍵或標識列的情況
如果視圖或查詢結果中有主鍵
/*
exec p_show
exec p_show
/*
因為要顧及通用性
exec p_show
*/
if exists (select * from dbo
drop procedure [dbo]
GO
CREATE Proc p_show
@QueryStr nvarchar(
@PageSize int=
@PageCurrent int=
@FdShow nvarchar (
@FdOrder nvarchar (
as
declare @FdName nvarchar(
declare @strfd nvarchar(
select @Obj_ID=object_id(@QueryStr)
[url=mailto:
end
[url=mailto:
end
[url=mailto:
else
[url=mailto:
) a
if @PageCurrent=
begin
select @Id
exec(
[url=mailto:
from
[url=mailto:
)
return
end
if @Obj_ID is not null and objectproperty(@Obj_ID
begin
select @Id
select @FdName=name from syscolumns where
[url=mailto:id=@Obj_ID]id=@Obj_ID[/url]
and status=
if @@rowcount=
begin
if not exists(select
[url=mailto:parent_obj=@Obj_ID]parent_obj=@Obj_ID[/url]
and xtype=
goto lbusetemp
select @FdName=name from syscolumns where
[url=mailto:id=@Obj_ID]id=@Obj_ID[/url]
and colid in(
select colid from sysindexkeys where @Obj_ID=id and indid in(
select indid from sysindexes where @Obj_ID=id and name in(
select name from sysobjects where xtype=
[url=mailto:parent_obj=@Obj_ID]parent_obj=@Obj_ID[/url]
)))
if @@rowcount>
begin
select @strfd=
select @strfd=@strfd+
from syscolumns where
[url=mailto:id=@Obj_ID]id=@Obj_ID[/url]
and colid in(
select colid from sysindexkeys where @Obj_ID=id and indid in(
select indid from sysindexes where @Obj_ID=id and name in(
select name from sysobjects where xtype=
[url=mailto:parent_obj=@Obj_ID]parent_obj=@Obj_ID[/url]
)))
select @strfd=substring(@strfd
goto lbusepk
end
end
end
else
goto lbusetemp
/*
lbuseidentity:
exec(
[url=mailto:
from
[url=mailto:
+
[url=mailto:
not in(select top
[url=mailto:+@Id
[url=mailto:
from
[url=mailto:
+
)
return
/*
lbusepk:
exec(
[url=mailto:
from(select top
[url=mailto:
a
(select top
[url=mailto:
) a
left join (select top
[url=mailto:
[url=mailto:
from
[url=mailto:
) b on
[url=mailto:
where
[url=mailto:
) a
)
return
/*
lbusetemp:
select @FdName=
exec(
[url=mailto:
into #tb
[url=mailto:from
select
[url=mailto:
from #tb where
[url=mailto:
between
[url=mailto:+@Id
and
[url=mailto:
)
GO
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22063.html