-
Mar 4th, 2014, 09:49 AM
#1
Thread Starter
New Member
convert currency sql
(
@Amount DECIMAL(18,2),
@Freight DECIMAL(18,2),
@FreightName VARCHAR(500)
)
AS
SELECT FreightName,
CASE WHEN (FreightName= @FreightName) And (UseFreight = 'TRUE') THEN
'$' + Convert(varchar(25), @freight,1
ElSE
'$' + Convert(varchar(25), 0.00,1
END AS Freight
FROM
tblFreightType
WHERE FreightName=@FreightName
when i execute the query it says cant convert varchar to numeric
-
Mar 4th, 2014, 10:00 AM
#2
Addicted Member
Re: convert currency sql
I think you left your trailing ) off your Convert Calls
Code:
'$' + Convert(varchar(25), @freight,1
ElSE
'$' + Convert(varchar(25), 0.00,1
Should be
Code:
'$' + Convert(varchar(25), @freight,1)
ElSE
'$' + Convert(varchar(25), 0.00,1)
I assumed that was a copy and paste error but I cannot recreate your bug.
This is what I tried
Code:
declare @tblFreightType table (FreightName VARCHAR(500))
insert into @tblFreightType values ('UPS')
declare @Amount DECIMAL(18,2)
declare @Freight DECIMAL(18,2)
declare @FreightName VARCHAR(500)
set @FreightName = 'UPS'
set @Freight = '2.32'
SELECT FreightName,
CASE WHEN (FreightName= @FreightName) THEN
'$' + Convert(varchar(25), @freight,1)
ElSE
'$' + Convert(varchar(25), 0.00,1 )
END AS Freight
FROM
@tblFreightType
WHERE FreightName=@FreightName
Maybe try Cast?
_____________
Tim
If anyone's answer has helped you, please show your appreciation by rating that answer.
When you get a solution to your issue remember to mark the thread Resolved.
reference links
-
Mar 4th, 2014, 10:04 AM
#3
Thread Starter
New Member
Re: convert currency sql
thank you very much thetimmer
-
Mar 4th, 2014, 01:55 PM
#4
Addicted Member
Re: convert currency sql
my pleasure, glad you got it worked out.
Remember to mark this thread resolved if it's working for you now.
_____________
Tim
If anyone's answer has helped you, please show your appreciation by rating that answer.
When you get a solution to your issue remember to mark the thread Resolved.
reference links
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|