Skip to content

added sql file - #1

Open
izalitzilant wants to merge 1 commit into
masterfrom
dev
Open

added sql file#1
izalitzilant wants to merge 1 commit into
masterfrom
dev

Conversation

@izalitzilant

Copy link
Copy Markdown
Owner

No description provided.

Comment thread Candidate_SQL.sql
@@ -0,0 +1,123 @@
create procedure syn.usp_ImportFileCustomerSeasonal
@ID_Record int
AS

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1
why UPPERCASE?

Comment thread Candidate_SQL.sql
where f.ID = @ID_Record
and f.FlagLoaded = cast(1 as bit)
)
begin

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2

-- `begin/end` на одном уровне с `if`

Comment thread Candidate_SQL.sql

raiserror(@ErrorMessage, 3, 1)
return
end

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3

-- `begin/end` на одном уровне с `if`

Comment thread Candidate_SQL.sql
-- Проверка на корректность загрузки
if not exists (
select 1
from syn.ImportFile as f

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4

В случае, если алиас представляет собой системное слово, добавляем первую согласную букву после заглавной из первого слова. -> imf

Comment thread Candidate_SQL.sql
or try_cast(isnull(cs.FlagActive, 0) as bit) is null

-- Обработка данных из файла
merge into syn.CustomerSeasonal as cs

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5

Перед названием таблицы, в которую осуществляется merge, into не указывается

Comment thread Candidate_SQL.sql
,c_dist.ID as ID_dbo_CustomerDistributor
,cast(isnull(cs.FlagActive, 0) as bit) as FlagActive
into #CustomerSeasonal
from syn.SA_CustomerSeasonal cs

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#6

Алиас обязателен для объекта и задается с помощью ключевого слова as

Comment thread Candidate_SQL.sql
set nocount on
begin
declare @RowCount int = (select count(*) from syn.SA_CustomerSeasonal)
declare @ErrorMessage varchar(max)

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#14

Рекомендуется при объявлении типов не использовать длину поля max

Comment thread Candidate_SQL.sql
Comment on lines +87 to +88
when matched
and t.ID_CustomerSystemType <> s.ID_CustomerSystemType then

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#15

-- Все дополнительные условия остаются на строке с "when"

when matched and t.ID_CustomerSystemType <> s.ID_CustomerSystemType then

Comment thread Candidate_SQL.sql
Comment on lines +53 to +55
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 'Невозможно определить Активность'

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#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 'Невозможно определить "Активность"'

Подразумевается что сущности таблицы т.к. с заглавной буквы.

Comment thread Candidate_SQL.sql
begin
set @ErrorMessage = 'Ошибка при загрузке файла, проверьте корректность данных'

raiserror(@ErrorMessage, 3, 1)

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#17

Пропущена

-- Пустая строка перед return

Comment thread Candidate_SQL.sql
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)
;

@izalitzilant izalitzilant Sep 28, 2024

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18

; ставится в конце последней строки конструкции merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant