Print Page | Close Window

If then in ASP

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Database Discussion
Forum Description: Discussion and chat on database related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=3458
Printed Date: 29 March 2026 at 7:40pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: If then in ASP
Posted By: PaulGQ
Subject: If then in ASP
Date Posted: 11 June 2003 at 4:21pm

I have an asp query pulling data from an access database.

What I need to do is display the data as follows

if value="ABC" then display it as "XYZ"

if value="DEF" then display it as "TUV"

I'd like to do this in the query in access and then just have my asp script point to the query for the data, or I can reformat the data in the asp script with i guess with something like the following:

<% if (rs.Fields("Customer").Value)= "ABC" then %>XYZ <% else =(rs.Fields("Customer").Value)%>

<% if (rs.Fields("Customer").Value)= "DEF" then %>TUV <% else =(rs.Fields("Customer").Value)%>

But this doesnt seem to work as I get an an unexpected next message or syntax error.

Any help is appreciated. 

 

 

 




Replies:
Posted By: Gullanian
Date Posted: 11 June 2003 at 4:32pm

<% if (rs.Fields("Customer").Value)= "ABC" then%>
XYZ
<% else

response.write(rs.Fields("Customer").Value)

end if%>



Posted By: PaulGQ
Date Posted: 11 June 2003 at 4:46pm

That works great for the ABC, but what about the DEF?

 

and GHI if we need to add it in down the road



Posted By: WebWiz-Bruce
Date Posted: 11 June 2003 at 4:50pm

Or you could use:-

<% 
If (rs.Fields("Customer").Value)= "ABC" then Response.Write("XYZ") else Response.Write(rs.Fields("Customer").Value)

if (rs.Fields("Customer").Value)= "DEF" then Response.Write("TUV") else Response.Write(rs.Fields("Customer").Value)
%>



-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: PaulGQ
Date Posted: 11 June 2003 at 5:00pm

boRg,

that returns "XYZDEF"



Posted By: WebWiz-Bruce
Date Posted: 11 June 2003 at 5:13pm
Place a vbCrLF of <br> or " " inbwteen the results so that they are not all together then.

-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: PaulGQ
Date Posted: 11 June 2003 at 6:09pm

INneed the results either one or the other, not both put together.

If I am misunderstanding you, can you please write out what you mean exactly?



Posted By: michael
Date Posted: 11 June 2003 at 7:20pm

<%
If (rs.Fields("Customer").Value)= "ABC" then Response.Write("XYZ")
ELSEIf (rs.Fields("Customer").Value)= "DEF" then Response.Write("TUV")
else Response.Write(rs.Fields("Customer").Value)
%>



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: PaulGQ
Date Posted: 11 June 2003 at 7:53pm

in that 3 line configuration, I get expected "then" error.

 

I appreciate the help though.



Posted By: WebWiz-Bruce
Date Posted: 12 June 2003 at 2:40am

<% 
If (rs.Fields("Customer").Value)= "ABC" then
      Response.Write("XYZ") 
ELSEIf (rs.Fields("Customer").Value)= "DEF" then 
      Response.Write("TUV")
else 
      Response.Write(rs.Fields("Customer").Value)
End If
%>



-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: Boecky
Date Posted: 12 June 2003 at 3:10am

Maybe you can try this:

<%
Dim strVal
strVal = Fields("Customer")
If strVal = "ABC" Then
 Response.Write("ABC")
Else
 Response.write("DEF")
End If
%>

Or you can use:

<%
Dim strVal
strVal = Fields("Customer")
Select Case strVal
 Case "ABC"
  Response.Write("ABC")
 Case "DEF"
  Response.Write("DEF")
 Else
  Response.Write("No customer")
End Select
%>




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net