CREATE PROCEDURE tt
@a varchar(100),
@b varchar(100)
AS
declare @c varchar(100),@d varchar(100)
select @c ='select * from tensile where '
if @a != ''
select @c=@c + 'tensile_unit = ' +@a
exec @c
if @b !=''
select * from tensile
GO
exec tt @a ='质检中心',@b=''服务器: 消息 2812,级别 16,状态 62,行 9
未能找到存储过程 'select * from tensile where tensile_unit = 质检中心'。
服务器: 消息 2812,级别 16,状态 62,行 13
未能找到存储过程 'select * from tensile where tensile_unit = 质检中心'。
@a varchar(100),
@b varchar(100)
AS
declare @c varchar(100),@d varchar(100)
select @c ='select * from tensile where '
if @a != ''
select @c=@c + 'tensile_unit = ' +@a
exec @c
if @b !=''
select * from tensile
GO
exec tt @a ='质检中心',@b=''服务器: 消息 2812,级别 16,状态 62,行 9
未能找到存储过程 'select * from tensile where tensile_unit = 质检中心'。
服务器: 消息 2812,级别 16,状态 62,行 13
未能找到存储过程 'select * from tensile where tensile_unit = 质检中心'。
if @a != ''
select @c=@c + 'tensile_unit = ' +@a
exec @c 这样构造??如果@a=''的时候..
那@c='select * from tensile where'
再用exec 执行就出错.exec (@c)
AS
begin
declare @c as varchar(100)
declare @d as varchar(100)
select @c ='select * from tensile where '
if @a <> ''
begin
select @c=@c + 'tensile_unit = ' +@a
exec @c
end
if @b <> ''
select * from tensile
end
GO exec tt @a ='质检中心',@b=''
CREATE PROCEDURE tt @a varchar(100), @b varchar(100)
AS
begin
declare @c as varchar(100)
declare @d as varchar(100)
select @c ='select * from tensile where '
if @a <> ''
begin
select @c=@c + 'tensile_unit = ' +@a
exec @c
end
if @b <> ''
select * from tensile
end
GO exec tt @a ='质检中心',@b=''
select @c=@c + 'tensile_unit = ''' +@a + ''''
exec (@c) --> 括号
AS
begin
declare @c as varchar(100)
declare @d as varchar(100)
select @c ='select * from customer where '
if @a <> ''
begin
select @c=@c + 'id = ' +@a
print @c
exec (@c)
end
if @b <> ''
select * from tensile
end
GO ID CustomerName Address Diector Phone re
----------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1434 三阳 待输入! 待输入! 待输入! 待输入!(所影响的行数为 1 行)
exec(@c)