日期:2014-05-17 浏览次数:20506 次
-- 用完整的产品列表填充该TABLE变量 INSERT INTO @Product SELECT ROW_NUMBER() OVER (ORDER BY Product.Id), Id, Nick,NumIid, TrackIiid,ContactPhone,CategoryId,CreateTime,ModifiedTime,Sorting,EffectiveIntegral,ShareIntegral FROM Product WHERE Id > 0 IF @Category > 0 AND CategoryId = @Category IF @Key <> '' AND Nick = @Key ORDER BY Id DESC
DECLARE @sql varchar(max) SET @sql=' SELECT ROW_NUMBER() OVER (ORDER BY Product.Id), Id, Nick,NumIid, TrackIiid,ContactPhone,CategoryId,CreateTime,ModifiedTime,Sorting,EffectiveIntegral,ShareIntegral FROM Product WHERE Id > 0 ' IF @Category > 0 BEGIN SET @sql=@sql+' AND CategoryId = @Category ' END IF @Key <> '' BEGIN SET @sql=@sql+' AND Nick = @Key ' END SET @sql=@sql+' ORDER BY Id DESC ' EXEC @sql