USE MainDatabase

UPDATE docType SET value = 'Другое' WHERE code = 601
GO

UPDATE docType SET value = 'Договор' WHERE code = 604
GO

UPDATE docType SET value = 'Контракт' WHERE code = 605
GO

UPDATE docType SET value = 'Акт' WHERE code = 606
GO

UPDATE docType SET value = 'CMR-накладная' WHERE code = 607
GO

UPDATE docType SET value = 'Счет-фактура' WHERE code = 608
GO

UPDATE docType SET value = 'Invoice (счет)' WHERE code = 609
GO

UPDATE docType SET value = 'Авизо' WHERE code = 610
GO

UPDATE docType SET value = 'Бухгалтерская справка' WHERE code = 611
GO

UPDATE docType SET value = 'Акт выполненных работ' WHERE code = 612
GO

UPDATE docType SET value = 'Коносамент' WHERE code = 613
GO

if not exists(SELECT * FROM syscolumns WHERE (name = 'refund') AND (id = OBJECT_ID(N'[dbo].[documents]')))
ALTER TABLE dbo.documents ADD [refund] [bit] NOT NULL DEFAULT(0)

GO

if not exists(SELECT * FROM syscolumns WHERE (name = 'additionalValue') AND (id = OBJECT_ID(N'[dbo].[documents]')))
ALTER TABLE dbo.documents ADD [additionalValue] [varchar](30)

GO

UPDATE d
SET refund=1
FROM documents d
     INNER JOIN invoices i ON d.idSender=i.idSender AND d.compilingYear=i.compilingYear and d.number=i.number
WHERE d.idSender=(SELECT idPredpr FROM tbNastrPredpr) and i.documentType<>1

