0

我有一个@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  ???
4

1 回答 1

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

于 2013-05-26T04:00:05.540 回答