added sql file - #1
Conversation
| @@ -0,0 +1,123 @@ | |||
| create procedure syn.usp_ImportFileCustomerSeasonal | |||
| @ID_Record int | |||
| AS | |||
| where f.ID = @ID_Record | ||
| and f.FlagLoaded = cast(1 as bit) | ||
| ) | ||
| begin |
There was a problem hiding this comment.
#2
-- `begin/end` на одном уровне с `if`
|
|
||
| raiserror(@ErrorMessage, 3, 1) | ||
| return | ||
| end |
There was a problem hiding this comment.
#3
-- `begin/end` на одном уровне с `if`
| -- Проверка на корректность загрузки | ||
| if not exists ( | ||
| select 1 | ||
| from syn.ImportFile as f |
There was a problem hiding this comment.
#4
В случае, если алиас представляет собой системное слово, добавляем первую согласную букву после заглавной из первого слова. -> imf
| or try_cast(isnull(cs.FlagActive, 0) as bit) is null | ||
|
|
||
| -- Обработка данных из файла | ||
| merge into syn.CustomerSeasonal as cs |
There was a problem hiding this comment.
#5
Перед названием таблицы, в которую осуществляется merge, into не указывается
| ,c_dist.ID as ID_dbo_CustomerDistributor | ||
| ,cast(isnull(cs.FlagActive, 0) as bit) as FlagActive | ||
| into #CustomerSeasonal | ||
| from syn.SA_CustomerSeasonal cs |
There was a problem hiding this comment.
#6
Алиас обязателен для объекта и задается с помощью ключевого слова as
| set nocount on | ||
| begin | ||
| declare @RowCount int = (select count(*) from syn.SA_CustomerSeasonal) | ||
| declare @ErrorMessage varchar(max) |
There was a problem hiding this comment.
#14
Рекомендуется при объявлении типов не использовать длину поля max
| when matched | ||
| and t.ID_CustomerSystemType <> s.ID_CustomerSystemType then |
There was a problem hiding this comment.
#15
-- Все дополнительные условия остаются на строке с "when"
when matched and t.ID_CustomerSystemType <> s.ID_CustomerSystemType then
| when try_cast(cs.DateBegin as date) is null then 'Невозможно определить Дату начала' | ||
| when try_cast(cs.DateEnd as date) is null then 'Невозможно определить Дату окончания' | ||
| when try_cast(isnull(cs.FlagActive, 0) as bit) is null then 'Невозможно определить Активность' |
There was a problem hiding this comment.
#16
Ссылка на сущности в таблице без "":
when try_cast(cs.DateBegin as date) is null then 'Невозможно определить "Дату начала"'
when try_cast(cs.DateEnd as date) is null then 'Невозможно определить "Дату окончания"'
when try_cast(isnull(cs.FlagActive, 0) as bit) is null then 'Невозможно определить "Активность"'
Подразумевается что сущности таблицы т.к. с заглавной буквы.
| begin | ||
| set @ErrorMessage = 'Ошибка при загрузке файла, проверьте корректность данных' | ||
|
|
||
| raiserror(@ErrorMessage, 3, 1) |
There was a problem hiding this comment.
#17
Пропущена
-- Пустая строка перед return
| when not matched then | ||
| insert (ID_dbo_Customer, ID_CustomerSystemType, ID_Season, DateBegin, DateEnd, ID_dbo_CustomerDistributor, FlagActive) | ||
| values (s.ID_dbo_Customer, s.ID_CustomerSystemType, s.ID_Season, s.DateBegin, s.DateEnd, s.ID_dbo_CustomerDistributor, s.FlagActive) | ||
| ; |
There was a problem hiding this comment.
#18
; ставится в конце последней строки конструкции merge
No description provided.