关键在
declare @intTmp int
set @intTmp=0
set @DSql = N'select @intTmp= 1 from dbo.syscolumns where name = ''isdeleted'' and id = object_id(''' + @TableName + ''')'
execute sp_executesql @Dsql, N'@intTmp int output', @intTmp output
if @intTmp=1能有什么好的办好代替它吗?
declare @intTmp int
set @intTmp=0
set @DSql = N'select @intTmp= 1 from dbo.syscolumns where name = ''isdeleted'' and id = object_id(''' + @TableName + ''')'
execute sp_executesql @Dsql, N'@intTmp int output', @intTmp output
if @intTmp=1能有什么好的办好代替它吗?
set @DSql = N'select 1 from dbo.syscolumns where name = ''isdeleted'' and id = object_id(''' + @TableName + ''')'
execute sp_executesql @DSql
if @@Rowcount >0
begin
end
else..
也有问题.
入:if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[P_GetDateByIntF]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[P_GetDateByIntF]
GO
可以里面有参数,调用不了.
如何办,大家帮帮我吧.
create PROCEDURE P_GetDateByIntF
(
@TableName nvarchar(50) , --表名
@TableCol nvarchar(50), --字段
@Filter nvarchar(500), --过虑条件
@TableColValue int --字段值
)
AS
/*----------------------------------------------------------
二: P_GetDateByIntF 注意用来通过 int 类型的 带过虑条件 收搜来获得需要的记录集
Wirten By 贺清华
Date : 2003-06-11
Where: wenzhou renben
----------------------------------------------------------*/
Declare @Dsql nvarchar(4000) --运行语句 注意一定要是 nvarchar类型
declare @intTmp int
set @intTmp=0
set @DSql = N'select @intTmp = 1 from dbo.syscolumns where name = ''isdeleted'' and id = object_id(@TableName)'
execute sp_executesql @Dsql, N'@TableName nvarchar(50),@intTmp int output',@TableName,@intTmp output
if @intTmp=1
begin
if @Filter = ''
set @Dsql = N'select * from ' + @TableName + ' where isdeleted=0 and ' + @TableCol + ' = ' + convert(nvarchar(20),@TableColValue)
else
set @Dsql = N'select * from ' + @TableName + ' where isdeleted=0 and ' + @TableCol + ' = ' + convert(nvarchar(20),@TableColValue) + ' and ' + @Filter
end
else
begin
if @Filter = ''
set @Dsql = N'select * from ' + @TableName + ' where ' + @TableCol + ' = ' + convert(nvarchar(20),@TableColValue)
else
set @Dsql = N'select * from ' + @TableName + ' where ' + @TableCol + ' = ' + convert(nvarchar(20),@TableColValue) + ' and ' + @Filter
end
execute sp_executesql @Dsql
return
begin
..................
end
可以了,可以给我讲讲这个为什么可以,我那个为什么不行的.