Wednesday, February 7, 2007

TSQL : Show all available DATETIME formats

SET NOCOUNT ON
SET NOCOUNT ON
DECLARE @tblDateTime TABLE (id TINYINT,DateString VARCHAR(30))
DECLARE @CurrentCount INT
DECLARE @TotalCount INT
DECLARE @DateLength INT
DECLARE @DateString VARCHAR(30)

SET @TotalCount = 150
SET @CurrentCount = 1 
WHILE @CurrentCount <= @TotalCount    
BEGIN       
BEGIN TRY  
SELECT @DateString = CONVERT(VARCHAR(30),GETDATE(),@CurrentCount)  
INSERT INTO @tblDateTime (id,DateString) VALUES(@CurrentCount,@DateString)  
END TRY  
BEGIN CATCH  
END CATCH 
SET @CurrentCount = @CurrentCount + 1   
END   
SELECT id,datestring FROM @tblDateTime 

No comments: