我有一个 sql 查询,它是一个价目表,我通常为 18 个不同的客户运行 18 个不同的时间。我有一个@varchar 作为声明,我更改了 customerID。然后导出一个 txt 平面文件文件,这样我就可以转换为 Excel 并通过 feebootimail 发送。
是否有可以在 sql 2005 中运行的例程,以便将客户列表输入并获取 18 个不同的 txt 文件?例如 Pricelist_8343.txt、Pricelist_8363.txt 等
DECLARE @CustNum varchar(20)
SELECT @CustNum = '7509'
SELECT
it.ITEMID 'item id'
,it.ItemGroupID
,it.ITEMNAME
,Convert(Decimal(9,0),itm.QUANTITY) 'Sales Multiple'
,Convert(Decimal(9,0),it.TAXPACKAGINGQTY) 'Price Break Qty'
,Convert(Decimal(9,0),it.OUTERQUANTITY) 'Carton Qty'
,Convert(Decimal(9,2),itm.PRICE) 'Part Pack'
,Convert(Decimal(9,2),itm.PRICE2) 'Full Pack'
,Convert(Decimal(9,2),round( CASE
WHEN pdt.AMOUNT >0 then pdt.amount
else CASE
when pdt.discpct is null then CASE
WHEN pdt.PRICELEVELTOUSE = 0 then Price
WHEN pdt.PRICELEVELTOUSE = 1 then Price2
WHEN pdt.PRICELEVELTOUSE = 2 then Price3
WHEN pdt.PRICELEVELTOUSE = 3 then Price4
WHEN pdt.PRICELEVELTOUSE = 4 then Price5
WHEN pdt.PRICELEVELTOUSE = 5 then Price6 END
when pdt.discpct = 0 then CASE
WHEN pdt.PRICELEVELTOUSE = 0 then Price
WHEN pdt.PRICELEVELTOUSE = 1 then Price2
WHEN pdt.PRICELEVELTOUSE = 2 then Price3
WHEN pdt.PRICELEVELTOUSE = 3 then Price4
WHEN pdt.PRICELEVELTOUSE = 4 then Price5
WHEN pdt.PRICELEVELTOUSE = 5 then Price6 END
when pdt.discpct > 0 then CASE
WHEN pdt.PRICELEVELTOUSE = 0 then round(itm.price - (itm.price*pdt.discpct/100),2)
WHEN pdt.PRICELEVELTOUSE = 1 then round(itm.price2 - (itm.price2*pdt.discpct/100),2)
WHEN pdt.PRICELEVELTOUSE = 2 then round(itm.price3 - (itm.price3*pdt.discpct/100),2)
WHEN pdt.PRICELEVELTOUSE = 3 then round(itm.price4 - (itm.price4*pdt.discpct/100),2)
WHEN pdt.PRICELEVELTOUSE = 4 then round(itm.price5 - (itm.price5*pdt.discpct/100),2)
WHEN pdt.PRICELEVELTOUSE = 5 then round(itm.price6 - (itm.price6*pdt.discpct/100),2) END END END ,2)) as 'TAPrice'
,upper(itm.unitid) 'UOM'
, Case
When itm.PRICECHANGESTATUS=3 then 'Increase'
When itm.PRICECHANGESTATUS=2 then 'Decrease'
When itm.PRICECHANGESTATUS=1 then 'New Item'
When itm.PRICECHANGESTATUS=0 then '-'
END 'Price Indicator'
from INVENTTABLE it
join INVENTTABLEMODULE itm on it.ItemId = itm.ItemID and itm.ModuleType = 2
join CUSTTABLE cust on LTRIM(cust.AccountNum) = @CustNum
left outer join PRICEDISCTABLE pdt on (ltrim(pdt.accountrelation) =
case
when pdt.accountcode = 0 then ltrim(cust.accountnum)
when pdt.accountcode = 1 then ltrim(cust.pricegroup) end)and
(ltrim(pdt.ItemRelation)+ltrim(pdt.UnitID) = case
when pdt.itemrelation = it.itemid then ltrim(it.ItemID)+ltrim(itm.Unitid)
when pdt.itemrelation = it.itempricegroup then ltrim(it.ItemPriceGroup)+ltrim(itm.Unitid)end
) and pdt.fromdate <= getdate() and (getdate()<= pdt.todate or pdt.todate = ' ')
join PriceLevelListReportLine sorter on it.ItemGroupID = sorter.ItemGroupID
and (it.ItemType = (case when sorter.linetype = 0 then '0'
when sorter.linetype = 1 then '0'
when sorter.linetype = 2 then '1'end)
or it.ItemType = (case when sorter.linetype = 1 then '1' end))
WHERE it.PRICELISTFlag=1
ORDER BY sorter.SortOrder, it.ItemID