Welcome to new things

[Technical] [Electronic work] [Gadget] [Game] memo writing

SQL Server

How to use Microsoft SQL Server with JavaScript

This is a memo on how to use Microsoft SQL Server (MSSQL) with JavaScript. The library is tedious, which is also recommended by Microsoft. tedios is a callback style library, but it is written in async, await, and TypeScript in a modern st…

How to add a read-only user to SQL Server (Azure SQL Database)

SQL Server data is read by BI tools to create graphs. In that case, we did not want to use a user with write permission because the data would only be read and various people would create graphs, so we created a read-only user for sharing.…

You should not write queries across databases in Azure SQL Database.

I did not know that SQL Server was the first time to use Azure SQL Database, but in SQL Server, queries across databases can be easily written by specifying the database, as shown below. SELECT * FROM [<db_name>].dbo.test_table However, when I try </db_name>…

How to do monthly/weekly aggregation in SQL Server

To aggregate data by month/week, first find the beginning date of the month/week of the date and GROUP by that beginning date. If the DATE_TRUNC() function can be used to get the head date, such as Google BigQuery, you can aggregate the da…

How to get the last record of a group in SQL

For example, "In a user's event log, I want to extract the last event the user performed." Sometimes you want to retrieve the last record of data divided by groups. The window function can be used to obtain the following WITH tbl AS ( SELE…

How to create a calendar table in SQL Server

I wanted a calendar table in SQL Server (Azure SQL Database), so here is a memo on how to create one. I googled, and it seems to be created by creating a table with "WITH" and then making a recursive call from "UNION ALL" in the table defi…