62,046
社区成员
发帖
与我相关
我的任务
分享
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 ?)
CREATE PROCEDURE [dbo].[sp_Users_List]
@userName nvarchar(50),
@realName nvarchar(50)
AS
declare @where varchar(200)
set @where =''
set @where =@where+ case isnull(@username,'') when '' then '' else ' and userName='''+@userName+'''' end
set @where =@where+ case isnull(@realName,'') when '' then '' else ' and realName='''+@realName+'''' end
exec('SELECT top 10 * FROM Users where 1=1 '+@where+' and id not in(select top 0 id from Users where 1=1 '+@where+'))')
CREATE PROCEDURE [dbo].[sp_Users_List]
@userName nvarchar(50),
@realName nvarchar(50)
AS
declare @sql varchar(500)
declare @where varchar(2000)
set @where='1=1'
if(@userName is not null and @userName !='')
set @where=@where+'and clumn0='+@userName
if(@realName is not null and @realName !='')
set @where=@where+'and clumn1='+@realName
set @sql='SELECT top 10 * FROM Users '+@where
exec @sql
SELECT top 10 * FROM Users where1=1 and (userName=@userName or @userName='') and (realName=@realName or @realName = '') and id not in(select top 0 from Users where and (userName=@userName or @userName = '') and (realName=@realName or @realName='')