

Lets combine the account number (comma separated values) with respect to the customer. Insert into tbl_Customer_Bank_Details Values (2,'Bob','B002') Insert into tbl_Customer_Bank_Details Values (2,'Bob','B001') Insert into tbl_Customer_Bank_Details Values (1,'Imran','A003') Insert into tbl_Customer_Bank_Details Values (1,'Imran','A002') Insert into tbl_Customer_Bank_Details Values (1,'Imran','A001') Let me create an example to explain this : Given below is the result.Īs mentioned above, I was working on a report where multiple Bank A/C # should be displayed next to the customer name like a comma separated field.

The result of all of the above methods is the same. SELECT STUFF((SELECT ', ' + FROM tbl_Currency FOR XML PATH('')),1,1,'') as This is the recommended / best way to do this because you can achieve the same result without any variable and less lines of code. Set + Coalesce(+ ', ','') from tbl_Currency Display Decimal Numbers As Money Without Cents To display Decimal Numbers to Money with Cents, it will require replacing the cents digit as the following: SELECT replace ( convert ( varchar, cast (floor(541777367.100000) as money),1), '. We can also achieve the same using COALESCE function. This is a simple way for development but performance wise it will costa lot for your application.įETCH NEXT FROM Cur_Cursor INTO as Insert into tbl_Currency Values ('British pound') Insert into tbl_Currency Values ('UAE dirham') Insert into tbl_Currency Values ('Philippine peso') Insert into tbl_Currency Values ('Pakistani rupee') Insert into tbl_Currency Values ('Indian rupee') Insert into tbl_Currency Values ('European euro') Insert into tbl_Currency Values ('US dollar') Let me create a simple example to explain these methods in detail. Lets say I have multiple currencies in a table and I would like to display in a single comma separated rows. I was preparing a statistical report and was stuck in one place where I needed to convert certain rows to comma separated values and put into a single row.
