这里有错误吗?

hssh38 2002-05-28 06:48:40
CREATE PROCEDURE [SearchBbs]
@Form int=0,
@Field varchar(30),
@Keyword nvarchar(255)='%'
AS
If @Form=0
select * from titles where Subject like @keyword order by LastNewsDate Desc
Else
select * from titles where BoardID=@Form and @Field like @keyword order by LastNewsDate Desc
GO
...全文
38 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
愉快的登山者 2002-05-29
  • 打赏
  • 举报
回复
If @Form=0
exec("select * from titles where "+@Field+" like "+@keyword+" order by LastNewsDate Desc")
Else
exec("select * from titles where BoardID="+@Form+" and "+@Field+ "like "+@keyword+" order by LastNewsDate Desc")
GO
hssh38 2002-05-29
  • 打赏
  • 举报
回复
急!
hssh38 2002-05-28
  • 打赏
  • 举报
回复
这个存储过程怎么不能执行呢,当参数传入时。这样行吗?
CREATE PROCEDURE [SearchBbs]
@Form int=0,
@Field varchar(30),
@Keyword nvarchar(255)='%'
AS
If @Form=0
select * from titles where @Field like @keyword order by LastNewsDate Desc
Else
select * from titles where BoardID=@Form and @Field like @keyword order by LastNewsDate Desc
GO

warning 2002-05-28
  • 打赏
  • 举报
回复
select * from titles where BoardID=@Form and @Field like @keyword order by 有错,要用动态sql
Jpp 2002-05-28
  • 打赏
  • 举报
回复
没看出语法的错误。

如果你建立时有错,可能与你的表有关。如表不存在、字段名错误。。。

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧