"IF" question

"IF" question

am 16.01.2006 14:36:22 von Paul Malbon

Hi,

I'm a low level coder, so please bear with me.

I have a table in a database with a field called 'company' I want to display
the value of that field in my application when there is a value in the
database, and display 'N/A' in the app when there is no value. The code I
have is as follows, and as you've guessed, it doesnt work.

company = rs("company") (record set has been established and pulls data down
ok)

If company = null Then
company = "N/A"
End IF

<%=company%>

Any assitance would be great.

Thanks in advance

Re: "IF" question

am 16.01.2006 14:41:21 von Jevon

Try:
If company IS null Then
...
End If


Jevon


"Paul Malbon" wrote in message
news:OOLFZHqGGHA.3916@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I'm a low level coder, so please bear with me.
>
> I have a table in a database with a field called 'company' I want to
> display the value of that field in my application when there is a value in
> the database, and display 'N/A' in the app when there is no value. The
> code I have is as follows, and as you've guessed, it doesnt work.
>
> company = rs("company") (record set has been established and pulls data
> down ok)
>
> If company = null Then
> company = "N/A"
> End IF
>
> <%=company%>
>
> Any assitance would be great.
>
> Thanks in advance
>

Re: "IF" question

am 16.01.2006 14:45:29 von unknown

<%
company = rs("company") & ""
If company = "" Then
company = "N/A"
End If
%>

<%=company%>

Try that.

Ray at work

"Paul Malbon" wrote in message
news:OOLFZHqGGHA.3916@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I'm a low level coder, so please bear with me.
>
> I have a table in a database with a field called 'company' I want to
> display the value of that field in my application when there is a value in
> the database, and display 'N/A' in the app when there is no value. The
> code I have is as follows, and as you've guessed, it doesnt work.
>
> company = rs("company") (record set has been established and pulls data
> down ok)
>
> If company = null Then
> company = "N/A"
> End IF
>
> <%=company%>
>
> Any assitance would be great.
>
> Thanks in advance
>

Re: "IF" question

am 16.01.2006 15:02:42 von reb01501

Paul Malbon wrote:
> Hi,
>
> I'm a low level coder, so please bear with me.
>
> I have a table in a database with a field called 'company' I want to
> display the value of that field in my application when there is a
> value in the database, and display 'N/A' in the app when there is no
> value. The code I have is as follows, and as you've guessed, it
> doesnt work.
>
> company = rs("company") (record set has been established and pulls
> data down ok)
>
> If company = null Then
> company = "N/A"
> End IF
>
> <%=company%>
>
> Any assitance would be great.
>
Just to expand on Ray's answer:
Nothing can ever be equal to (=) Null. "Null" means that the value is
"unknown", so the result of any comparison or calculation involving Null
will result in Null. The only exception to this rule in vbscript is
concatenation (&): when you concatenate Null to a string, you get that
string returned. Ray's solution takes advantage of that exception.

In vbscript, you can use the IsNull() function to test whether a value is
null or not. For more information see:
http://blogs.msdn.com/ericlippert/archive/2003/09/30/53120.a spx
http://blogs.msdn.com/ericlippert/archive/2003/10/01/53128.a spx


In SQL, you can use the Is operator to test whether a column or variable
contains Null:
WHERE somecolumn Is Null
Bob Barrows


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: "IF" question

am 16.01.2006 15:20:00 von Paul Malbon

Thanks very much, it works a treat!

Paul

"Ray Costanzo [MVP]" wrote in
message news:erWSeMqGGHA.3984@TK2MSFTNGP14.phx.gbl...
> <%
> company = rs("company") & ""
> If company = "" Then
> company = "N/A"
> End If
> %>
>
> <%=company%>
>
> Try that.
>
> Ray at work
>
> "Paul Malbon" wrote in message
> news:OOLFZHqGGHA.3916@TK2MSFTNGP10.phx.gbl...
>> Hi,
>>
>> I'm a low level coder, so please bear with me.
>>
>> I have a table in a database with a field called 'company' I want to
>> display the value of that field in my application when there is a value
>> in the database, and display 'N/A' in the app when there is no value. The
>> code I have is as follows, and as you've guessed, it doesnt work.
>>
>> company = rs("company") (record set has been established and pulls data
>> down ok)
>>
>> If company = null Then
>> company = "N/A"
>> End IF
>>
>> <%=company%>
>>
>> Any assitance would be great.
>>
>> Thanks in advance
>>
>
>