SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share
Donate
Blog
Popular
Donate
A
A
A
Share
Blog
Popular
SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code.
You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.
SQL code:
Upload
Copy
Format
Clear
create procedure syn.usp_ImportFileCustomerSeasonal @ID_Record int as set nocount on begin declare @RowCount int = (select count(*) from syn.SA_CustomerSeasonal) declare @ErrorMessage varchar(max) -- Проверка на корректность загрузки if not exists ( select 1 from syn.ImportFile as f where f.ID = @ID_Record and f.FlagLoaded = cast(1 as bit) ) begin set @ErrorMessage = 'Ошибка при загрузке файла, проверьте корректность данных' raiserror(@ErrorMessage, 3, 1) return end CREATE TABLE #ProcessedRows ( ActionType varchar(255), ID int ) --Чтение из слоя временных данных select cc.ID as ID_dbo_Customer ,cst.ID as ID_CustomerSystemType ,s.ID as ID_Season ,cast(cs.DateBegin as date) as DateBegin ,cast(cs.DateEnd as date) as DateEnd ,cd.ID as ID_dbo_CustomerDistributor ,cast(isnull(cs.FlagActive, 0) as bit) as FlagActive into #CustomerSeasonal from syn.SA_CustomerSeasonal cs join dbo.Customer as cc on cc.UID_DS = cs.UID_DS_Customer and cc.ID_mapping_DataSource = 1 join dbo.Season as s on s.Name = cs.Season join dbo.Customer as cd on cd.UID_DS = cs.UID_DS_CustomerDistributor and cd.ID_mapping_DataSource = 1 join syn.CustomerSystemType as cst on cs.CustomerSystemType = cst.Name where try_cast(cs.DateBegin as date) is not null and try_cast(cs.DateEnd as date) is not null and try_cast(isnull(cs.FlagActive, 0) as bit) is not null -- Определяем некорректные записи -- Добавляем причину, по которой запись считается некорректной select cs.* ,case when cc.ID is null then 'UID клиента отсутствует в справочнике "Клиент"' when cd.ID is null then 'UID дистрибьютора отсутствует в справочнике "Клиент"' when s.ID is null then 'Сезон отсутствует в справочнике "Сезон"' when cst.ID is null 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 'Невозможно определить Активность' end as Reason into #BadInsertedRows from syn.SA_CustomerSeasonal as cs left join dbo.Customer as cc on cc.UID_DS = cs.UID_DS_Customer and cc.ID_mapping_DataSource = 1 left join dbo.Customer as cd on cd.UID_DS = cs.UID_DS_CustomerDistributor and cd.ID_mapping_DataSource = 1 left join dbo.Season as s on s.Name = cs.Season left join syn.CustomerSystemType as cst on cst.Name = cs.CustomerSystemType where cc.ID is null or cd.ID is null or s.ID is null or cst.ID is null or try_cast(cs.DateBegin as date) is null or try_cast(cs.DateEnd as date) is null or try_cast(isnull(cs.FlagActive, 0) as bit) is null end
SQL
Server:
MariaDB 11.4
MariaDB 11.5
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
MySQL 5.7
MySQL 5.7 Sakila (ReadOnly)
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 11
PostgreSQL 12
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
Version
ER Diagram
Preserve result
Stuck with a problem?
Got Error?
Ask ChatGPT!
Result:
Copy
Clear