求一存储过程写法

骑猪看海 骑猪看海 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

CREATE PROCEDURE [dbo].[sp_Users_List]
@userName nvarchar(50),
@realName nvarchar(50)
AS
BEGIN
SELECT top 10 * FROM Users where1=1 ? and id not in(select top 0 from Users where1=1 ?)

@userName 和 @realName是 查询条件

本来应该这样写的:
SELECT top 10 * FROM Users where1=1 and userName=@userName and realName=@realName and id not in(select top 0 from Users where and userName=@userName and realName=@realName)

但有时传进来的可能是空,所以不能写死,值为空时and条件应该去除,不然就找不出数据,应该怎么写。
以前一直不用存储过程,直接在程序中用字符串把条件拼起来的,现在用下就不知道怎么做了,各位看看怎么应该做
...全文

相关推荐

评论 13
收藏 已收藏
分享
返回顶部
骑猪看海
.NET社区 62,274 成员 668,968 内容