Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - check for existing database record
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

check for existing database record

 Post Reply Post Reply
Author
coolnlstuff View Drop Down
Newbie
Newbie
Avatar

Joined: 26 April 2003
Location: Netherlands
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote coolnlstuff Quote  Post ReplyReply Direct Link To This Post Topic: check for existing database record
    Posted: 18 June 2003 at 8:17am

OK i have this record in the table Users in my database

User_ID: 31
FirstName:  John
LastName:  Doe
DOB:  12-01-1950

Now I want to check if that record realy exists in the database with the following sql-query:

firstname = "John"
lastname = "Doe"
dob = "12-01-1950"

sql_UserExists = ""
sql_UserExists = sql_UserExists & "SELECT User_ID "
sql_UserExists = sql_UserExists & "FROM Users "
sql_UserExists = sql_UserExists & "WHERE Firstname = '"& HQ(firstname) &"' "
sql_UserExists = sql_UserExists & "AND LastName = '"& HQ(lastname) &"' "
sql_UserExists = sql_UserExists & "AND DOB = "& CDate(dob) &" "

the HQ-function removes the ' from the string

and I check it with:

SET rs_UserExists = Server.CreateObject("ADODB.Recordset")
rs_UserExists.Open sql_UserExists, Conn
UserExists = NOT(rs_UserExists.BOF AND rs_UserExists.EOF)
rs_UserExists.Close
SET rs_UserExists = Nothing

now UserExists has the value FALSE, but when I remove the line:

sql_UserExists = sql_UserExists & "AND DOB = "& CDate(dob) &" "

it has the value TRUE, so something must be wrong with the last line, but I cannot see what it is...

I also included the Session.LCID = 1043 statement for the way dates are represented



Edited by coolnlstuff
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 18 June 2003 at 10:14am

Depending on what database you are using, you need to wrap the data value in single quotes or # signs

SQL:
sql_UserExists = sql_UserExists & "AND DOB = '"& CDate(dob) &"' "

Access:
sql_UserExists = sql_UserExists & "AND DOB = #"& CDate(dob) &"# "

Contribute to the working anarchy we fondly call the Internet
Back to Top
coolnlstuff View Drop Down
Newbie
Newbie
Avatar

Joined: 26 April 2003
Location: Netherlands
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote coolnlstuff Quote  Post ReplyReply Direct Link To This Post Posted: 18 June 2003 at 12:30pm

Tnx I, i use Acces...and it works with the #'s!!!

Are there more of those #'s or ''s you have to use with integers, strings or dates?

Is there a list availabe somewhere?

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 18 June 2003 at 1:23pm

In either:
- Strings get single quotes
- Numbers dont

Access Dates
- wrapped in #'s

SQL Dates
- wrapped in single quotes

Contribute to the working anarchy we fondly call the Internet
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.