I have to display time in a weird format. For example, if time is 15:30:45.5000, I need to display "153045.5".
To do this, I have the following query:
SELECT LEFT(CONVERT(varchar(20), GETDATE(), 114), 2) +
SUBSTRING(CONVERT(varchar(20), GETDATE(), 114), 4, 2) +
SUBSTRING(CONVERT(varchar(20), GETDATE(), 114), 7, 2) + '.' +
SUBSTRING(CONVERT(varchar(20), GETDATE(), 114), 10, 1);
Is there anything I can do to avoid repeating the expression CONVERT(varchar(20), GETDATE(), 114)?
Edit:
I saw a really cool answer here which was deleted for some reason after I refreshed the page, but it gave me the idea to think of an alternative solution:
SELECT REPLACE(RIGHT(CONVERT(varchar(21), getdate(), 126), 10), ':', '')
Although this answer doesn't solve the original question in a generic way, it still solves my problem in a different way.