convert

  • I am doing some optimization and am looking for anything that will help.

    I have some code as follows

    Declare @mxid numeric(18,0)

    select @mxid = max(convert(numeric(18,0),id_c)) + 1 from ra.trmstr

    id_c is a character field, I know, it shouldn't be but it is. If I don't do the convert, since it is a character, it thinks 9089 is larger than 12098. When I try cast, it is about the same performance wise. Is this optimized fully or can it be tweaked?

    Thanks,

    Eddie

  • You are using numeric(18,0) for the conversion so does the field hold only integers (no decimals)? If so then you could try converting to an int datatype instead. In a small test I ran selecting 1 million rows converting to an int ran in 2 seconds compared to 3 for converting to numeric(18,0). Alternatively you could trigger inserts into id_c into a new numeric field and select from there, this would impair insert performance though.

    Regards,

    Andy Jones

    andyj93@hotmail.com

    .

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

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