In a database table (SQL Server 2012), I have dates saved in the yyyyxxx format, where xxx is the day of the year. For example 2015-08-11
yyyyxxx
xxx
2015-08-11
Since there is a good answer for the first question, let's talk about the second one.
How about converting DATETIME to this format?
DATENAME function can help to solve it. It's gonna look like that:
SELECT DATENAME(year, @var) + RIGHT('00' + DATENAME(dayofyear, @var), 3)