Выгрузка для сайтов организовывается созданием задания на выполнение скриптов, с периодичностью до минуты. Результатом выгрузки является создание файла формата *.xml, в который выгружаются все данные карточки товара, а также остаток по складу и продажная цена.
1. Выбираем нужную базу и в ней создаём процедуру:
Отрабатываем скрипт 1
Отрабатываем скрипт 2
2 На основании скрипта3 создаем джоб
3 Создаём job согласно содержимому файла (Job) с ОБЯЗАТЕЛЬНЫМ указанием базы, к которой мы добавили процедуру в предыдущем шаге.
4 Настраиваем job, пользуемся выгруженной номенклатурой в формате xml.
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
Create Procedure dbo.sp_PutFile
@FilePath VARCHAR(Max),
@Text1 NVARCHAR(MAX),
@Text2 NVARCHAR(MAX)=null,
@Text3 NVARCHAR(MAX)=null,
@Text4 NVARCHAR(MAX)=null,
@Text5 NVARCHAR(MAX)=null
AS
BEGIN TRY
DECLARE @objFileSystem int
,@objTextStream int
,@objErrorObject int
,@FileData Varchar(8000)
,@RC int
,@EOF int
,@Text nvarchar(max)
SET NOCOUNT ON
--create FSO
EXEC @RC = sp_OACreate 'Scripting.FileSystemObject' , @objFileSystem OUT
IF @RC <> 0 GOTO FSO_ERROR
SET @objErrorObject=@objFileSystem
-- open FSO
EXEC @RC = sp_OAMethod @objFileSystem , 'OpenTextFile'
,@objTextStream OUT, @FilePath, 2, True
IF @RC <> 0 GOTO FSO_ERROR
SET @objErrorObject=@objTextStream
set @Text=isnull(@Text1,'')+isnull(@Text2,'')+isnull(@Text3,'')+isnull(@Text4,'')+isnull(@Text5,'')
--write FSO
EXEC @RC = sp_OAMethod @objTextStream, 'Write', Null, @Text
IF @RC <> 0 GOTO FSO_ERROR
--Close FSO
EXEC @RC = sp_OAMethod @objTextStream, 'Close'
IF @RC <> 0 GOTO FSO_ERROR
EXEC @RC=sp_OADestroy @objTextStream
IF @RC <> 0 GOTO FSO_ERROR
GOTO FINISH
FSO_ERROR:
--this part unfinished
DECLARE @Source varchar(255) ,@Description Varchar(255) ,@Helpfile Varchar(255), @HelpID int
EXEC @RC=sp_OAGetErrorInfo @objErrorObject
,@source output, @Description output, @Helpfile output,@HelpID output
IF COALESCE(@Description,'') = ''
SET @Description='Cannot open or write file "' + @filePath + '"'
SET @Text=NULL
RETURN @RC
FINISH:
RETURN 0
END TRY
BEGIN CATCH
--put error handling here
--RAISERROR (ERROR_MESSAGE(),ERROR_SEVERITY(),@ERROR_STATE())
RETURN Error_Number()
END CATCH
declare @rc int,@var nvarchar(max)
set @var=(select * from (
select isnull(ass1001,0) as Artikul
,rtrim(ass1003) as ArtName
,rtrim(ass3002) as Barcod
,rtrim(ass2007) as NameGos
,rtrim(ass2008) as Annotation
,rtrim(isnull(cls2004,'')) as EI
,rtrim(isnull(str1003,'')) as Strana
,isnull(gru2003,0) as Kod_Gruppa
,rtrim(isnull(gru2004,'')) as Gruppa
,rtrim(ass2031) as nomenklator
,isnull(ass2032,0) as model
,max(TPR2011) as Price
,sum(TPR2006) as Qty
from tpr2
inner join ass1 on ass1001 = tpr2004
inner join ass2 on ass2001 = ass1001
left join ass3 on ass3001 = ass1001 and ass3004=1
left outer join ass4 on ass1.ass1001 = ass4.ass4001 and ass4.ass4002 = (select gru1001 from gru1 where gru1003=1)
left outer join gru2 on ass4.ass4003 = gru2.gru2001 and gru2002=ASS4002
left join cls2 on cls2001 = ass1005 and cls2002=100
left join str1 on str1001 = ass2002
where tpr2006>0 and tpr2007=1
group by ass1001
,ass1003
,ass3002
,ass2007
,cls2004
,gru2003
,gru2004
,str1003
,ass2031
,ass2032
,ass2008
)tovar
for xml auto
)
exec @rc=sp_PutFile N'd:\onix_price.xml'
,N'<?xml version="1.0" encoding="windows-1251"?><Articles>'
,@var
,N'</Articles>'
select @rc