Combine CONVERT with ROUND

  • Hi. I have a SQL query that uses convert to modify the output of 2 fields as follows:

    1) ISNULL(CONVERT(VARCHAR(12),SUM(QuantityOutstanding)),'0.00')AS Quantity

    2) '£' + CONVERT (VARCHAR(12),StandardPrice,1)AS StandardPrice

    I would like to control the output to 2 decimal places. I understand that the ROUND function will support this. Can I combine CONVERT with ROUND (not a programmer so syntax example would be great).

    The data is intended for display on a web page. For some reason MS Visual Web Developer 2008 will not apply the formatting {0:F2} even with HtmlEncode set to false so I thought maybe the better approach would be for the sql query to do the formatting for me.

    Many Thanks,

    Phil.

    -------------------------------------------------------------------------------------
    A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

    Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

    Tommy Cooper

  • For some reason MS Visual Web Developer 2008 will not apply the formatting {0:F2} even with HtmlEncode set to false so I thought maybe the better approach would be for the sql query to do the formatting for me.

    I don't think this is a good approach: try fixing the page instead of converting numbers to a different data type.

    -- Gianluca Sartori

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply