0
0

More than 1 year has passed since last update.

SQLServer で TEXT型(yyyyMMddHHmmss) を日付型に変換する

Posted at

SQLServer のデータをVB.net で select , Delete する際に

create_dtm,update_dtm がテキスト型だったため、過去日付のデータを狙って削除する、ということにひと手間必要でした。

その覚書き。


delete from 'テーブル名'"                              
where convert(DateTime,stuff(stuff(stuff(update_dtm, 9, 0, ' '), 12, 0, ':'),15, 0, ':'))

と、記述することによりテキスト型のdtmを日付型に変換。

仮に1年以上前の場合削除、といった条件をつける場合は、


delete from 'テーブル名'"                              
where convert(DateTime,stuff(stuff(stuff(update_dtm, 9, 0, ' '), 12, 0, ':'),15, 0, ':')) <= (select DATEADD(month,(-13), GETDATE()))

というイメージになる。

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