2011/11/07

Convert DateTime to String in SQLServer

DECLARE @tmpDate TABLE
(
    [Formart Expression] NVARCHAR(10),
    [Converted Date] NVARCHAR(100)    
)

DECLARE @i INT
DECLARE @style NVARCHAR(10)
SET @i = 1

WHILE @i <= 50
BEGIN    
    SET @style = CONVERT(INT, '100') + CONVERT(INT, @i)        
    BEGIN try
        INSERT INTO @tmpDate ([Formart Expression] , [Converted Date])
        SELECT @style, CONVERT(NVARCHAR(100), GETDATE(), CONVERT(INT, @style))
    END TRY
    BEGIN CATCH
    END CATCH
    SET @i = @i + 1    
END

SELECT * FROM @tmpDate

No comments:

Post a Comment

 What is AI? Artificial Intelligence (AI) is the ability of machines or computer systems to perform tasks that normally require human intell...