我有一张表@MyTemp
,如下所示:
|Name |Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday |
-----------------------------------------------------------------
|Test |18:30 |15:40 |15:40 |17:30 |18:30 |08:30 |09:30 |
我知道我可以使用
在SQL Server中度过一天DECLARE @Today NVARCHAR(50) = (SELECT datename(dw,getdate()))
如何在我的选择
中获得一天的结果SELECT @Today From @MyTemp ???
答案 0 :(得分:2)
怎么样
SELECT
CASE datename(dw,getdate())
WHEN 'Monday' THEN Monday
WHEN 'Tuesday' THEN Tuesday
WHEN 'Wednesday' THEN Wednesday
WHEN 'Thursday' THEN Thursday
WHEN 'Friday' THEN Friday
WHEN 'Saturday' THEN Saturday
WHEN 'Sunday' THEN Sunday
END today
FROM @MyTemp
WHERE Name = 'Test'
示例输出:
| TODAY |
---------
| 09:30 |
<强> SQLFiddle 强>