Assume that you have money filed in your table and want to
convert as string. Money filed value in SQL with value “10000.0000” when
converted returns a value as “10000.0000”.
But the desired output is 10000.00.
CREATE TABLE [dbo].[tblSalary](
[Salary]
[money] NULL
) ON
[PRIMARY]
1.
Using
Cast Function:
SELECT CAST(CAST(Salary AS DECIMAL(18,2)) AS VARCHAR)
FROM
[tblSalary]
2.
Using
Convert with Cast Function:
SELECT CONVERT(varchar(20), CAST(Salary AS DECIMAL(18,2)), 0)
FROM [Employee].[dbo].[tblSalary]
3.
Using
Convert with Round Function:
SELECT CONVERT(varchar, ROUND(Salary,2), 0)
FROM [Employee].[dbo].[tblSalary]
Cheers,
Venkatesan Prabu .J
Managing Director – KaaShiv Info Tech / MSP-MVP Mentor
www.kaashivinfotech.com
No comments:
Post a Comment