存储过程根据参数值不同查询动态的列
本帖最后由 chai1338 于 2013-09-16 15:09:39 编辑
if @FromPT<>'all'
WHILE @Next <= dbo.Get_StrArrayLength(@ProductIDs,',') --循环id集合
BEGIN
SET @CurrProductID = CONVERT(int,dbo.Get_StrArrayStrOfIndex(@ProductIDs,',',@Next))
INSERT INTO #ProductTmp ([FromPT],[ProductId], [Price])
SELECT
p.FromPT,
P.ProductID,
ISNULL((SELECT MIN(cn_Price) FROM Nop_Productvariant WHERE ProductID = P.ProductId and FromPT=@FromPT),0) AS Price
FROM
Nop_Product P
WHERE
P.ProductID = @CurrProductID AND Deleted = 0
and p.FromPT=@FromPT
SET @Next=@Next+1
END
if @FromPT<>'all'
WHILE @Next <= dbo.Get_StrArrayLength(@ProductIDs,',') --循环id集合
BEGIN
SET @CurrProductID = CONVERT(int,dbo.Get_StrArrayStrOfIndex(@ProductIDs,',',@Next))
INSERT INTO #ProductTmp ([FromPT],[ProductId], [Price])
SELECT p.FromPT,P.ProductID,
case @FromPT when'中国' then cn_Price when'英国' then en_Price end as price
FROM Nop_Product P
LEFT JOIN Nop_Productvariant T ON T.ProductID = P.ProductId AND T.FromPT=@FromPT
WHEREP.ProductID = @CurrProductID AND Deleted = 0 and p.FromPT=@FromPT
SET @Next=@Next+1
END