Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I want to convert this formula into the string '0612' and not equal 18. How would I convert this?(SUBSTRING(CONVERT(nvarchar(6), CURRENT_TIMESTAMP, 112),5,2)) + (YEAR(GETDATE())%100)Gregory Cardullo
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-06-12 : 09:34:58
Cast the second part also to string
CAST((YEAR(GETDATE())%100) AS VARCHAR(2))
An alternate approach:
SELECTRIGHT( '0'+CAST(MONTH(CURRENT_TIMESTAMP) AS VARCHAR(2)) +CAST((YEAR(GETDATE())%100) AS VARCHAR(2)),4)
There may be even simpler ways using the appropriate convert style. http://msdn.microsoft.com/en-us/library/ms187928.aspx
jimf
Master Smack Fu Yak Hacker
2875 Posts
Posted - 2012-06-12 : 10:06:23
right(convert(varchar(10),current_timestamp,112),4)JimEveryday I learn something that somebody else already knew