0

В базе данных MSSQL хранятся Аукционы и у каждого аукциона есть прикрепленный MS Word документ. Вот мой скрипт с запросом.

DECLARE @Comm as varchar(400)


DECLARE Business CURSOR FOR

SELECT v.ID,p.document_id, p.pageno, p.extensions
FROM docum.dbo.Document v join docum.dbo.v_docpage_wr p on (p.document_id = v.ID)
where p.kind != '1' and v.Datefrom >= '2015.01.01' and v.Datefrom <= '2015.01.31'
ORDER BY v.ID, p.document_id, p.pageno, p.extensions

OPEN Business
FETCH NEXT FROM Business
INTO @ID, @Docum,@PageNo,@Extension

WHILE @@FETCH_STATUS = 0
BEGIN


SET @Comm = 'bcp "SELECT cast ([body] as ...)  FROM [docum].[dbo].[v_docpage_wr] WHERE [ID] =  ''' +cast(@ID  as nvarchar(50))+ '''"  queryout "C:\Auction\' + cast(@Docum as nvarchar(50)) + '-'  + cast(@PageNo as nvarchar(20)) + '.' + cast(@Extension as nvarchar(20)) +'" -T  '

 PRINT @Comm

EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE

  EXECUTE master..xp_cmdshell @Comm
    FETCH NEXT FROM Business
    INTO @ID, @Docum,@PageNo,@Extension

END

CLOSE Business
DEALLOCATE Business

Какой формат данных нужно указать в функции cast()?

4

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Посмотрите другие вопросы с метками или задайте свой вопрос.