根據變量類型:·有VARCHAR,日期和時間
Declare @open varchar(max), @closed varchar(max)
--Declare @open DateTime, @closed DateTime
--Declare @open Time, @closed Time
Select @open = '7AM'
, @closed = '8AM'
select Substring(CONVERT(VARCHAR(MAX),cast(@open as datetime), 8),1,2)
+ Substring (CONVERT(VARCHAR(MAX),cast(@Closed as datetime), 8),1,2)
作爲一個有用的asside,我有每當我與日期跳舞這個片段店/測試時間格式:
WITH lv0 AS (SELECT 0 g UNION ALL SELECT 0)
,lv1 AS (SELECT 0 g FROM lv0 a CROSS JOIN lv0 b) -- 4
,lv2 AS (SELECT 0 g FROM lv1 a CROSS JOIN lv1 b) -- 16
,lv3 AS (SELECT 0 g FROM lv2 a CROSS JOIN lv2 b) -- 256
,Tally (n) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM lv3)
SELECT CAST(n AS VARCHAR(MAX)) + ' - ' + CONVERT(VARCHAR(MAX),cast('1/1/11 7AM' as datetime), n) xZample
, 'CONVERT(VARCHAR(MAX),@YouMindIfWeDanceWitYourDates, '+CAST(n AS VARCHAR(25))+')' AS _________________________tehcode____________________________
FROM Tally
WHERE (n< 200) AND (n%100 IN (0,20,21,120,121,126,127,130,131) OR n%100 <= 14)
ORDER BY n;
我有一個偷偷摸摸的懷疑,可能是這種情況..不要認爲REXSTER允許功能。這就是爲什麼我需要存儲過程... – JGFMK
我試圖回答別人的帖子在堆棧溢出,他們的開始臨時表留下了很多不盡人意的地方。是要試圖將其映射到合理的東西。所以列開始爲字符串.. – JGFMK