'IF' question

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
Paul Malbon [ Mo, 16 Januar 2006 14:36 ] [ ID #1143765 ]

Re: 'IF' question

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

<%=company%>

Try that.

Ray at work

"Paul Malbon" <nospam [at] all.com> wrote in message
news:OOLFZHqGGHA.3916 [at] 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
>
my first name at lane [ Mo, 16 Januar 2006 14:45 ] [ ID #1143766 ]

Re: 'IF' question

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


Jevon


"Paul Malbon" <nospam [at] all.com> wrote in message
news:OOLFZHqGGHA.3916 [at] 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
>
Jevon [ Mo, 16 Januar 2006 14:41 ] [ ID #1143767 ]

Re: 'IF' question

Thanks very much, it works a treat!

Paul

"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:erWSeMqGGHA.3984 [at] TK2MSFTNGP14.phx.gbl...
> <%
> company = rs("company") & ""
> If company = "" Then
> company = "N/A"
> End If
> %>
>
> <%=company%>
>
> Try that.
>
> Ray at work
>
> "Paul Malbon" <nospam [at] all.com> wrote in message
> news:OOLFZHqGGHA.3916 [at] 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
>>
>
>
Paul Malbon [ Mo, 16 Januar 2006 15:20 ] [ ID #1143768 ]

Re: 'IF' question

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.
reb01501 [ Mo, 16 Januar 2006 15:02 ] [ ID #1143769 ]
Webserver » microsoft.public.inetserver.asp.db » 'IF' question

Vorheriges Thema: Access To Access
Nächstes Thema: bound control