Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2004, 12:50 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default SELECT statement...strange problem

To start a "Request For Order", users can do a couple of things.
1. Go to our vendor table and click a vendor link which will send the "key" field for that record to the RFO and automaticly fill in user information. The key field is a auto generated number.
2. Enter either the organization's FEIN (Federal ID)which will send the "fein" files format= 12-3456789 to the RFO for lookup.
3. Enter a University ID number for that organization "uiid"...format= People: 123456789 Organization: @12345678

my RFO works great for everything unless I type in the vendor uiid (@12345678)...I get the error message 'No value given for one or more required parameters.' FUNNY THING...it works fine for People uiid's (123456789)

sSQL = "SELECT * " & _
  " FROM vendor" & _
  " WHERE fein = '" & Request.Form("search_string") & "'" & _
  " OR uiid = '" & Request.Form("search_string") & "'" & _
  " OR key = " & Request.Form("search_string")
Set rs = Connect.Execute(sSQL)


however if I make this small change it works fine for Organization uiin's (@12345678) but of course it now does not work when sending a "key" field after the user clicks on a vendor link.

sSQL = "SELECT * " & _
  " FROM vendor" & _
  " WHERE fein = '" & Request.Form("search_string") & "'" & _
  " OR uiid = '" & Request.Form("search_string") & "'"
Set rs = Connect.Execute(sSQL)

Does anyone understand this?

 
Old March 16th, 2004, 12:54 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Are you using SQL Server?

In SQL Server, parameters in Stored Procedures start with an @ symbol. So, I think your @12345678 is interpreted as a variable with the name 12345678.

What datatype is key in the database? It looks like a text type (char, varchar etc), because of the @. In that case, you'll need to enclose its value in apostrophes as well:

" OR key = '" & Request.Form("search_string") & "'"

Cheers,

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 16th, 2004, 01:12 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

when I enclose the Request.Form for the key field...my page does not work when sending a key threw. It's a AutoNumber Long Integer

Maybe I should write an If...if it coming from the vendor lookup use
sSQL = "SELECT * " & _
  " FROM vendor" & _
  " WHERE fein = '" & Request.Form("search_string") & "'" & _
  " OR uiid = '" & Request.Form("search_string") & "'"
Set rs = Connect.Execute(sSQL)

else use
 sSQL = "SELECT * " & _
  " FROM vendor" & _
  " WHERE key = " & Request.Form("search_string")
Set rs = Connect.Execute(sSQL)

Ill bet that will work...?

 
Old March 16th, 2004, 01:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

How can an auto number contain an @ symbol??

Or should people enter a key without the @? In that case, your last solution is close. How about this:

If Left(Request.Form("search_string"), 1) = "@" Then
  ' First char is an @
  sSQL = "SELECT * " & _
    " FROM vendor" & _
    " WHERE fein = '" & Request.Form("search_string") & "'" & _
    " OR uiid = '" & Request.Form("search_string") & "'"
Else
  sSQL = "SELECT * " & _
    " FROM vendor" & _
    " WHERE key = " & Request.Form("search_string")
End If


Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 16th, 2004, 01:58 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

I'm sorry the "@number" is a user ID number
the autonumber is the key field.
The reason the "@number" in not the key field is because organizations may have more than one address needing more than one entry.

 
Old March 16th, 2004, 02:02 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

User can enter
Person UID = "123456789"
Business UID = "@12345678"
or
User can click on link in vendor table
Key field is sent

 
Old March 16th, 2004, 02:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, either way, examine the value the user entered. If it contained an @, treat it as a string, and use it for string type column, and enclose its value in apostrophes.

If it doesn't contain an @, treat it as a number. You can still pass it to string type columns, enclosed in apostrophes, but now you can also pass it to (Auto)number column type, without the apostrophes


Does that make sense?

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 16th, 2004, 02:34 PM
Authorized User
 
Join Date: Jul 2003
Posts: 41
Thanks: 0
Thanked 1 Time in 1 Post
Default

I used your code...and of course it works.
Thank you again Imar;)






Similar Threads
Thread Thread Starter Forum Replies Last Post
New Bie- Select Statement problem sparsh2010 Access VBA 1 January 22nd, 2008 01:00 PM
Problem with SELECT INTO statement 132591 SQL Language 1 November 27th, 2006 06:58 AM
SQL select statement problem shrisangeeta Classic ASP Databases 3 June 15th, 2006 10:28 AM
Problem with "where = " select statement shirley65 SQL Language 3 October 17th, 2005 04:07 PM
Problem with select statement s.abraham ASP.NET 1.0 and 1.1 Basics 2 March 24th, 2005 02:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.