存储过程参数为条件拼接写法
代码参考:
if exists(select * from sysobjects where name='P_CardListPage') drop procedure P_CardListPage go create procedure P_CardListPage @Conditions varchar(max), @StartRow varchar(10), @EndRow varchar(10) as begin Declare @sql varchar(max) begin set @sql= 'select * from( select ROW_NUMBER() over(order by c.SeqNum) as rows,c.*,m.MealName,e.EName,u.UName from [CardManagerDB].[dbo].[CardTables] c inner join [CardManagerDB].[dbo].[CardMeals] m on c.MealID = m.MealID left join [CardManagerDB].[dbo].[Employees] e on c.Administrators = e.EID left join[EquipmentManageSystemDB].[dbo].[Sys_User] u on c.Administrators = u.EId ) as joinModel where '+@Conditions+' and rows between '+@StartRow+' and '+@EndRow+ 'order by CardOverTime desc' end exec(@sql) end go