How can i get result “My Dream Table Result”
CREATE TABLE #temp(
[count] int
, [Time] nvarchar(50))
DECLARE @DateNow DATETIME,@i int
SET @DateNow='00:00'
SET @i=1;
WHILE(@i<1440)
BEGIN
SET @DateNow=DATEADD(minute, 1, @DateNow)
INSERT INTO #temp ([count], [Time]) VALUES (0, @DateNow)
SET @i=@i+1
END
SELECT [count],CONVERT(VARCHAR(max), [Time], 104) AS [Time] FROM #temp
DROP TABLE #temp
Table Result:
Count | Time
-----------------------------
0 | Jan 1 1900 12:01AM
0 | Jan 1 1900 12:02AM
0 | Jan 1 1900 12:03AM
0 | Jan 1 1900 12:04AM
But i don’t like this table Time format is not ok. I need this table
My Dream Table Result:
Count | Time
0 | 12:01
0 | 12:02
0 | 12:03
0 | 12:04
...
...
0 | 22:01
0 | 22:02
0 | 22:03
0 | 22:04
@DateNow is a DateTime so will have the Date Compoent as well
will give you just the time component for putting in yoru Nvarchar column
And for shits’n’giggles, here’s how to do it without relying on a DateTime Object.