-- Test this function :
-- SELECT dbo.NumericToCurrency (1116548238,'US') AS RetValue
-- SELECT dbo.NumericToCurrency (10000,'IND') AS RetValue
-- For Indian Format - 'IND', FOR US Format - 'US'
CREATE FUNCTION [dbo].[NumericToCurrency]
(
@InNumericValue MONEY
,@InFormatType VARCHAR(10)
)
RETURNS VARCHAR(50)
AS
BEGIN
DECLARE @RetVal VARCHAR(50)
,@StrRight VARCHAR(5)
,@StrFinal VARCHAR(50)
,@StrLength INT
SET @RetVal = ''
SET @RetVal = @InNumericValue
SET @RetVal = SUBSTRING(@RetVal,1,CASE WHEN CHARINDEX('.', @RetVal)= 0 THEN LEN(@RetVal)
ELSE CHARINDEX('.', @RetVal)-1 END)
IF(@InFormatType = 'US')
BEGIN
SET @StrFinal = CONVERT(VARCHAR(50), CONVERT(money, @RetVal) , 1)
SET @StrFinal = SUBSTRING(@StrFinal,0,CHARINDEX('.',...