How do I cast the figure 2000.00 to the integer 2000?

  • How do I cast the figure 2000.00 to the integer 2000? 

  • Select CONVERT(INT, YouColHere) FROM dbo.YourTable WHERE Whatever = @SomeParam

     

    BTW Presenting the data in the correct format is often better left to the front end but there are a lot of exceptions!

  • CAST(ROUND(year, 0) AS int) AS Expr1

    is an alternative solution

  • You shouldn't need to do a cast at all in general. For example:

    DECLARE @fp MONEY

    DECLARE @i INT

    SET @fp = 2000.00

    SET @i = @fp

    will work fine.

    If you run SELECT @fp after this you'll get 2000.00, and if you run SELECT @i you'll get 2000. BOL is pretty good for answering questions like this.

    Thanks,

    Bart

  • SELECT CAST(2000.00 AS INT)

  • Why?  Not trying to be a smart guy here but why do you want to do such a conversion?  A lot of times, folks will come to the conclusion that there's something that they need to do and post only that... and that sometimes means they are missing a much better solution.  You could start off by explaining what the number 2000.00 represents and why you need to display it as an INT.  For example, is it a date/year?  If so, you may be making a huge mistake by handling it separately from the Month and Day....

    Like I said, what does the number 2000.00 represent and why do you think it needs to be converted?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

Viewing 6 posts - 1 through 5 (of 5 total)

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