CREATE PROCEDURE ypesearch
@typeid int,
@num int
AS
set nocount on
begin
select top @num * from news where typeid=@typeid and checkked=1
end
GO
===================提示我第七行'@num'附近有错误.如果这样写就没有错:CREATE PROCEDURE ypesearch
@typeid int,
@num int
AS
set nocount on
begin
select top 7 * from news where typeid=@typeid and checkked=1
end
GO为什么?到第第一种写法哪里出错了
@typeid int,
@num int
AS
set nocount on
begin
select top @num * from news where typeid=@typeid and checkked=1
end
GO
===================提示我第七行'@num'附近有错误.如果这样写就没有错:CREATE PROCEDURE ypesearch
@typeid int,
@num int
AS
set nocount on
begin
select top 7 * from news where typeid=@typeid and checkked=1
end
GO为什么?到第第一种写法哪里出错了
@typeid int,
@num int
AS
begin
set nocount on
declare @s varchar(1000)
set @s=''
set @s=@s+'select top'+cast(@num as varchar)+' * from news where typeid=@typeid and checkked=1'
end
GO
(
@typeid int,
@num int
)
AS
set nocount on
begin
exec('select top '+convert(varchar(20),@num)+' * from news where typeid='+convert(varchar(20),@typeid)+' and checkked=1'
end
GO
@typeid int,
@num int
AS
begin
set nocount on
declare @s varchar(1000)
set @s=''
set @s=@s+'select top'+cast(@num as varchar)+' * from news where typeid=@typeid and checkked=1'
exec(@s)
end
GO
少了个exec(@s)
不好意思