Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cond Statement for Field

    I have data coming in from a SQL table into 2 fields on a page. In one of those fields i want to display the actual data its getting from that SQL table for that field only if there are conditions not met. If the 2 conditions are met I want to display just a value that I specify.

    EX....this is an active 911 calls site and the field im wanting this for is the complaint type field. For like a Domestic call i want that field to say LAW ENF instead of Domestic which is what would come form the SQL table. I have a field in my table called "call class" that i can say if call class="X" then do this and so on.....

    I need something for ASP for this field that im showing for the complaint type on the page that will do this for me.

    Any ideas??

    Thanks

    Chris

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    you pretty much had it down with your statement above about doing the if

    If dbcolumn = "Domestic" Then
    Response.Write("LAW ENF")
    End If
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the line that is currently there for the complaint:

    <&#37;=(rsCAD.Fields.Item("Complaint").Value)%>

    Where would I put that code at??? Also I am wanting to use another field within the same table thats not shown to decide whether or not to show the actual complaint type. Like if the call class = L then it would display LAW ENF and the call class "L" comes from a field within that table???

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's what i have come up with messing around:

    <&#37;if (rsCAD.Call_Class) = "L" Response.Write ("LAW ENF") else if (rsCAD.Call_Class) = "M" Response.Write ("MEDICAL") else (rsCAD.Fields.Item("Complaint").Value)%>

    It doesn't work, i keep getting syntax errors.....this what i want to do though...

    Please help.

    Chris

  • #5
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    <&#37;
    if (rsCAD.Call_Class) = "L" then
    Response.Write ("LAW ENF")
    elseif (rsCAD.Call_Class) = "M" then
    Response.Write ("MEDICAL")
    else
    (rsCAD.Fields.Item("Complaint").Value)
    end if
    %>
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #6
    New Coder
    Join Date
    Jul 2008
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now i get this

    Syntax error

    /publicsafetyportal/publicsafety.asp, line 123

    if (rsCAD.Call_Class) = "L" then
    ----------------------^

  • #7
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    at a guess its because rsCAD.Call_Class isn't actually a column.

    <&#37;
    if (rsCAD.Fields.Item("Call_Class").Value) = "L" then
    Response.Write ("LAW ENF")
    elseif (rsCAD.Fields.Item("Call_Class").Value) = "M" then
    Response.Write ("MEDICAL")
    else
    (rsCAD.Fields.Item("Complaint").Value)
    end if
    %>


    something like that perhaps i'm affraid my ASP from DB work is a bit flakey though in my old scripts I used to do it like this.

    rs.open "select * from tblPosts where ID="&escape(request.querystring("show")) , Conn
    if rs.EOF then
    response.write "Invalid Blog ID please return to the blog mainpage."
    else
    if rs("content")="nobby" then
    response.write "nooby"
    end if
    end if


    hope that helps a little
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #8
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    It's because Call_Class isn't a property of the recordset object. It's a member in the recordset's fields collection.

    You can access it with:
    Code:
    rsCAD("Call_Class")
    Or, a bit better:

    Code:
    rsCAD.Fields("Call_Class")
    Try this:

    Code:
    <%
    strCallClass = rsCAD.Fields("Call_Class").Value
    if strCallClass = "L" then
    	Response.Write "LAW ENF"
    elseif strCallClass = "M" then
    	Response.Write "MEDICAL"
    else
    	Response.Write strCallClass 
    end if
    %>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •