0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

並び替えして楽に値を取得する方法【SQL Server】

Last updated at Posted at 2019-12-02

並び替えしてTOP1を変数に代入する。

例えば、日付を取得したい場合に使用できる。

対象日付 曜日
20191120 水曜日
20191121 木曜日
20191122 金曜日
20191123 土曜日
20191124 日曜日
SELECT TOP 1 @取得日付 = DateTable.対象日付
FROM (
      SELECT 対象日付
      FROM カレンダー
      WHERE 対象日付 <= @指定納期
     ) DateTable
ORDER BY 対象日付 DESC

業務系システムであれば、
リードタイムから納期を算出したり、
出荷予定日を算出する場合に便利かと。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?