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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Combining to calculation strings

Author  Topic 

cardullo4321
Starting Member

40 Posts

Posted - 2012-06-12 : 09:14:41
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:
SELECT
RIGHT(
'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
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-12 : 10:06:23
right(convert(varchar(10),current_timestamp,112),4)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -