...

View Full Version : Cond Statement for Field



stanleyc
09-02-2008, 10:33 PM
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

hinch
09-02-2008, 11:09 PM
you pretty much had it down with your statement above about doing the if

If dbcolumn = "Domestic" Then
Response.Write("LAW ENF")
End If

stanleyc
09-03-2008, 01:44 AM
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???

stanleyc
09-03-2008, 05:34 AM
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

hinch
09-03-2008, 11:09 AM
<&#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
%>

stanleyc
09-03-2008, 01:40 PM
Now i get this

Syntax error

/publicsafetyportal/publicsafety.asp, line 123

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

hinch
09-03-2008, 02:10 PM
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

Spudhead
09-04-2008, 02:11 PM
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:

rsCAD("Call_Class")

Or, a bit better:


rsCAD.Fields("Call_Class")

Try this:



<%
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
%>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum