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
-- Variables DECLARE @ControlValue INT = 25; DECLARE @StartDT DATETIME = '2024-07-17 16:25:00'; DECLARE @EndDT DATETIME = '2024-07-17 17:59:00'; DECLARE @StartHour INT = DATEPART(HOUR, @StartDT); DECLARE @EndHour INT = DATEPART(HOUR, @EndDT); -- Create the temporary table CREATE TABLE #TempTable ( HE1 INT, HE2 INT, HE3 INT, HE4 INT, HE5 INT, HE6 INT, HE7 INT, HE8 INT, HE9 INT, HE10 INT, HE11 INT, HE12 INT, HE13 INT, HE14 INT, HE15 INT, HE16 INT, HE17 INT, HE18 INT, HE19 INT, HE20 INT, HE21 INT, HE22 INT, HE23 INT, HE24 INT ); -- Initialize the temporary table with 0s INSERT INTO #TempTable VALUES (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); -- Update the relevant HE columns based on the ControlValue and Start/End hours DECLARE @HEColumn NVARCHAR(10); DECLARE @Hour INT = 1; WHILE @Hour <= 24 BEGIN SET @HEColumn = 'HE' + CAST(@Hour AS NVARCHAR(2)); IF @Hour >= @StartHour AND @Hour <= @EndHour BEGIN EXEC('UPDATE #TempTable SET ' + @HEColumn + ' = ' + CAST(@ControlValue AS NVARCHAR(10))); END SET @Hour = @Hour + 1; END -- Select the result SELECT * FROM #TempTable; -- Drop the temporary table DROP TABLE #TempTable;
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
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