

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: 取出自定义条数的最新视频
-- =============================================
ALTER PROCEDURE [dbo].[news_selectByNum]
@num int
AS
BEGIN
-- 定义@test和@sql两个参数,负责接收传来的@num和搭建字符串数组用
declare @test int, @sql varchar(2000);
select @test = @num;
set @sql = 'select top ' + cast(@test as varchar(10)) + '
n.id, n.title, n.createTime , c.[name] from news n
inner join category c on n.caId = c.id
order by n.createTime desc'
exec(@sql)
END