导出excel [原创]
create proc search_goods_all;2
@ToID int,@stortype int,@os int
as
select 'ID','编码','名称','单位','产品型号','账面库存','实际数量','货号','备注'
union all
select convert(varchar,ID),Code,[Name],Unit,Model,'0',convert(varchar,(SELECT isnull(sum(CC0),0)
FROM cInventory WHERE (GoodsID = cgoods.ID)
AND (ToID = @ToID) and stortype=@stortype and os=@os)),ImgNum,''
from cgoods
create proc outExcel
@ToID int,@stortype int,@os int
as
declare @s varchar(8000)
set @s = 'bcp "exec yqkc_jxc.dbo.search_goods_all;2 '+
ltrim(@ToID)+','+ltrim(@stortype)+','+ltrim(@os)+' " queryout "c:\盘点单.xls" -c -S"." -U"sa" -P"sa"'
EXEC xp_cmdshell @s