hour、minute、second都不是SQL Server的函数。
要取小時、分鐘和秒,都要使用datepart函数。
另外直接相加的得到的结果是数字相加,而不是字符串合并,需要转换成varchar
update person set id_no = cast(year(in_date) as varchar(4))+ cast(month(in_date) as varchar(2)) + cast(day(in_date) as varchar(2)) + cast(datepart(hh,in_date) as varchar(2)) + cast(datepart(mi,in_date) as varchar(2)) + cast(datepart(ss,in_date) as varchar(2))
selectconvert(char,getdate(),108)
08:56:56
select datename(hour,getdate())+':'+datename(minute,getdate())+':'+datename(second,getdate())
二.显示每周函数
SELECT
CASE (DATEPART(dw, GETDATE()) + @@DATEFIRST) % 7
WHEN 1 THEN 'Sunday'
WHEN 2 THEN 'Monday'
WHEN 3 THEN 'Tuesday'
WHEN 4 THEN 'Wednesday'
WHEN 5 THEN 'Thursday'
WHEN 6 THEN 'Friday'
WHEN 0 THEN 'Saturday'
END AS DayOfWeekName
DayOfWeekName
-------------
Wednesday
SET LANGUAGE N'简体中文'
SELECT DATENAME(weekday, GETDATE()) as DayOfWeekName
--SELECT name FROM sys.syslanguages
已将语言设置更改为 简体中文。
DayOfWeekName
------------------------------
星期三
(1 行受影响)
显然第三种方案在MSSQL中是最简洁的写法,那个LANGUAGE参数可以参考系统表得到:
SELECT name FROM sys.syslanguages
name
--------------------------------------------------------------------------------------------------------------------------------
us_english
Deutsch
Français
日本語
Dansk
Español
Italiano
Nederlands
Norsk
Português
Suomi
Svenska
čeština
magyar
polski
română
hrvatski
slovenčina
slovenski
ελληνικά
български
русский
Türkçe
British
eesti
latviešu
lietuvių
Português (Brasil)
繁體中文
한국어
简体中文
Arabic
ไทย
(33 行受影响)
全剧终