如何写查询的存储过程? 即当userName不为空时,把UserName拼写到where 条件后.(模糊查询) 自己写了,在Where UserName like ' + '%' + @userName + '%'
处报错.请大家帮忙看看.
CREATE PROCEDURE [dbo].[FindUser]
-- Add the parameters for the stored procedure here
@userName varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON; -- Insert statements for procedure here
DECLARE @_SelectSql nvarchar(1000)
SET @_SelectSql = N'SELECT * from UserInfor' IF @userName IS not null AND LEN(@userName) > 0
BEGIN
SET @_SelectSql = @_SelectSql + N' Where UserName like ' + '%' + @userName + '%'
END EXEC sp_executesql @_SelectSql
END
处报错.请大家帮忙看看.
CREATE PROCEDURE [dbo].[FindUser]
-- Add the parameters for the stored procedure here
@userName varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON; -- Insert statements for procedure here
DECLARE @_SelectSql nvarchar(1000)
SET @_SelectSql = N'SELECT * from UserInfor' IF @userName IS not null AND LEN(@userName) > 0
BEGIN
SET @_SelectSql = @_SelectSql + N' Where UserName like ' + '%' + @userName + '%'
END EXEC sp_executesql @_SelectSql
END
解决方案 »
- ext 文件上传问题
- [flyin2006]asp.net有没有演示工具?
- VS2005下如何实现文件上传到SQL数据库
- 活动月历,用.NET如何实现?在线等~谢谢
- 大家看看,FindControls为什么用数据绑定就不成了?
- Can Theme be related to different CSS file in different conditions?
- 关于两个ListBox的传值与删除item问题
- 发送Email问题请帮助解决一下谢谢
- 点Sever端控件后表单数据全被清空了啊?!-急
- 已经有人提过,但是情况好像有点不同,datagrid的翻页不能
- 用VisualStudio.net2003创建项目出错,急啊,高手请进(答复了就给分)!!!!!
- 如何从sql server2005 的xml字段读取xml文本直接显示在浏览器上,不生成临时文件
CREATE PROCEDURE [dbo].[FindUser]
-- Add the parameters for the stored procedure here
@userName varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON; -- Insert statements for procedure here
DECLARE @_SelectSql nvarchar(1000)
SET @_SelectSql = N'SELECT * from UserInfor' IF @userName IS not null AND LEN(@userName) > 0
BEGIN
SET @_SelectSql = @_SelectSql + N' Where UserName like ' + ''%' + @userName + '%'''
END EXEC sp_executesql @_SelectSql
END