1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SQLSeverクエリチートシート(自分用)

Last updated at Posted at 2024-08-10

はじめに

備忘録用です。

時間系

現在時刻の取得(日本時間)

DATEADD(hh,9,GETUTCDATE())

テーブル内の日付データの最古のデータと現在の日付差分を取得する

SELECT
  DATEDIFF(DAY, MIN(tableA.hiduke_data), DATEADD(hh,9,GETUTCDATE())) as '日付差分'
FROM tableA

日付データを文字列に変換する

SELECT
  -- CONVERT(変換後のデータ型, 日付データ, format指定数値) 
  CONVERT(NVARCHAR, hiduke_data,121) as 'yyyy-MM-dd hh:mi:ss.mmm'
  , CONVERT(NVARCHAR,hiduke_data,120) as 'yyyy-MM-dd hh:mi:ss'
  , CONVERT(NVARCHAR,hiduke_data, 23) as 'yyyy-MM-dd'
FROM tableA

文字列操作系

数値⇨文字列変換

CONVERT(nvarchar,1000)

文字列長算出

LEN('hogehoge')

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?