--Datetime型の日付データを年月日に分割する
DECLARE @currdate Datetime
SET @currdate = getDate()
Print @currdate
Print DATEPART(YEAR,@currdate)
Print DATEPART(MONTH,@currdate)
Print DATEPART(DAY,@currdate)
Print DATEPART(HOUR,@currdate)
Print DATEPART(MINUTE,@currdate)
Print DATEPART(SECOND,@currdate)
【結果】
04 30 2008 7:26PM
2008
4
30
19
26
29
2008年4月30日水曜日
【MSSQL】新規にINSERTしたレコードのIDを取得する方法
--新規にINSERTしたレコードのIDを取得する方法
--INSERTを実行した直後に@@IDENTITYの値を取得する。
INSERT INTO [dbo].[TEST]
([data1])
VALUES('test value')
Print 'New ID is ' + CONVERT(VARCHAR,@@IDENTITY)
--INSERTを実行した直後に@@IDENTITYの値を取得する。
INSERT INTO [dbo].[TEST]
([data1])
VALUES('test value')
Print 'New ID is ' + CONVERT(VARCHAR,@@IDENTITY)
登録:
投稿 (Atom)