SELECT 'D' + LEFT(CAST(num AS VARCHAR(4))+'0000',4)
FROM abc
SELECT ISNULL('D' + LEFT(CAST(NULLIF(num,0) AS VARCHAR(4))+'0000',4),'0')
FROM abc
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden