How to join Values

 Author Message kiran.rajenimbalkar Ten Centuries Group: General Forum Members Points: 1011 Visits: 331 Hi Professional ,Create Table,`CREATE TABLE abc(num int)`Insert Into `insert into abc values (1010)insert into abc values (111)insert into abc values (99)insert into abc values (0)``SELECT 'D'+ CAST(num AS NVARCHAR) FROM abc`Now I am getting Result as below,D1010D111D99D0But I have to show result as like below,D1010D1110D99000So please suggest me how to do this ?Regards,KRAj ChrisM@Work SSC Guru Group: General Forum Members Points: 96630 Visits: 20680 `SELECT 'D' + LEFT(CAST(num AS VARCHAR(4))+'0000',4) FROM abcSELECT ISNULL('D' + LEFT(CAST(NULLIF(num,0) AS VARCHAR(4))+'0000',4),'0') FROM abc` “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail ShawFor 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 ModenExploring Recursive CTEs by Example Dwain Camps dwain.c SSC-Forever Group: General Forum Members Points: 44103 Visits: 6431 Or like this:`SELECT CASE num WHEN 0 THEN '' ELSE 'D' END + RIGHT(num*POWER(10, 3-FLOOR(LOG10(CASE num WHEN 0 THEN 1 ELSE num END))), 4)FROM abc`What??? :-P My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!My thought question: Have you ever been told that your query runs too fast?My advice:INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.Need to UNPIVOT? Why not CROSS APPLY VALUES instead?Since random numbers are too important to be left to chance, let's generate some!Learn to understand recursive CTEs by example.Splitting strings based on patterns can be fast!My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables kiran.rajenimbalkar Ten Centuries Group: General Forum Members Points: 1011 Visits: 331 Thanks Experts Its work !