if statement on cast function possible?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omar999
    New Member
    • Mar 2010
    • 120

    #1

    if statement on cast function possible?

    I have the following cast function which multiplys a column value by 1.1 to display on a webpage.
    Code:
    SELECT *, Twin_Band_1 = Cast( Twin_Band_1 * 1.1 as int) FROM MYTABLENAME WHERE ID = '1'"
    if twin_band_1 = NULL in sql db isit possible to display '-' instead or a   or any other text for that matter?

    thanks in advance
    Omar.
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    No both of those are strings and you are casting the field as int

    How about something like this

    Cast( isnull(Twin_Ban d_1,-1) * 1.1 as int)


    and then on the webpage check for -1.1 and convert it to " " or "-"

    Comment

    • omar999
      New Member
      • Mar 2010
      • 120

      #3
      thanks delerna - I've tried your suggestion but no joy as the webpage displays "False"
      Code:
      Twin_Band_1 = Cast( isnull(Twin_Band_1,-1) * 1.1 as int)
      Code:
      Response.Write "<td>" & objRS("Twin_Band_1") = replace(objRS("Twin_Band_1"), "-1", "testreplace") & "</td>"
      not sure where im going wrong?

      Comment

      • omar999
        New Member
        • Mar 2010
        • 120

        #4
        iv figured this out - wohoo. I've used my original sql cast function with corrected asp code as follows;
        Code:
        ]SELECT *, Twin_Band_1 = Cast( Twin_Band_1 * 1.1 as int) FROM MYTABLENAME WHERE ID = '1'"
        Code:
        Response.Write "<td>" & replace(objRS(Trim("Twin_Band_1")), "-1", "-") & "</td>"
        thanks anyway
        omar.

        Comment

        • Delerna
          Recognized Expert Top Contributor
          • Jan 2008
          • 1134

          #5
          always good to see someone figure out their own problem.
          Thanks for the update.

          Comment

          Working...