Thursday, 2 June 2011

Format Date and year like CDR201106


Format Date and year like CDR201106

Format the date and year like CDR201106 by taking current month and year. By using Left, Len command of sql server.

DECLARE @VAR varchar(50)

SELECT  @VAR = 'CDR' + convert(varchar(4),YEAR(getdate())) + left('000', 2- len(month(getdate()))) + CONVERT(varchar(2),month(getdate()))

No comments:

Post a Comment