我有这个SQL语句我希望将'date'和'dayOfWeek'列结合起来
SELECT CONVERT(date,startTimeStamp) AS DATE
, datename(dw,CONVERT(date,startTimeStamp)) as dayOfWeek
,CONVERT(time,[startTimeStamp])AS StartTime
,CONVERT(time,[endTimeStamp])AS EndTime
,DATEDIFF(HH,[startTimeStamp] ,[endTimeStamp])
FROM [TaskManagementSystem_DB].[dbo].[Timesheet_entry]
答案 0 :(得分:2)
听起来你想要这个:
SELECT CONVERT(date,startTimeStamp) AS DATE
, datename(dw,CONVERT(date,startTimeStamp)) as dayOfWeek
,cast(datename(dw,CONVERT(date, startTimeStamp)) as varchar(50)) -- add this
+ ' ' + -- add this
CONVERT(varchar(50),CONVERT(date,startTimeStamp)) FullDate -- add this
,CONVERT(time,[startTimeStamp])AS StartTime
,CONVERT(time,[endTimeStamp])AS EndTime
,DATEDIFF(HH,[startTimeStamp] ,[endTimeStamp])
FROM [TaskManagementSystem_DB].[dbo].[Timesheet_entry]
要将字段连接在一起,您必须cast()
将它们设置为相同的数据类型,类似于:
select cast(datename(dw,CONVERT(date, getdate())) as varchar(50))
+ ' ' +
CONVERT(varchar(50) ,getdate()) newdate