convert currency sql-VBForums
Results 1 to 4 of 4

Thread: convert currency sql

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2013
    Posts
    9

    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

  2. #2
    Addicted Member thetimmer's Avatar
    Join Date
    Jan 2014
    Location
    Plano, Texas
    Posts
    243

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2013
    Posts
    9

    Re: convert currency sql

    thank you very much thetimmer

  4. #4
    Addicted Member thetimmer's Avatar
    Join Date
    Jan 2014
    Location
    Plano, Texas
    Posts
    243

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.