存储过程语法错误
请帮我看一下,这个存储过程语法错误问题,因为我不熟,找了半天也没找到原因,谢谢了。
sql 存储过程
CREATE PROCEDURE [dbo].[proc_get_pic_By_key]
@topnum int,
@wherestr NVARCHAR(250)
AS
BEGIN
select top @topnum photo_name,minipic from photo where minipic<>'' @wherestr order by picid desc
END
CREATE PROCEDURE [dbo].[proc_get_pic_By_key]
@topnum int,
@wherestr NVARCHAR(250)
AS
BEGIN
exec('select top '+@topnum +' photo_name,minipic from a where minipic<>'''''+@wherestr +' order by picid desc')
END
ALTER PROCEDURE [dbo].[proc_get_pic_By_key]
@topnum int,
@wherestr NVARCHAR(250)
AS
BEGIN
DECLARE @sql NVARCHAR(max)
SET @sql = N'
select top (@topnum) photo_name,minipic from photo where minipic<>'''' '+ @wherestr +' order by picid desc
'
PRINT @sql
EXEC sp_executesql @sql, N'@topnum int', @topnum
END
GO
EXEC [proc_get_pic_By_key] 1, 'AND minipic = ''TEST'''