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 August 30th, 2006, 08:24 AM
Authorized User
 
Join Date: Aug 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query statement has nonexistent field names-FIXED

In an asp/vbscript/sql/dreamweaver mx website I inherited, having this problem:

It appears that the query that the creator of the page wrote is looking for a start date (2000, for example) and an end date (2099) to be pulled from the SQL database "date" field for various events. There is no field existing called "startyear" or "start" or "endyear" or "end" -- just the "date" field currently exists in the database. when you try to run this coded page, you get various errors, such as:

Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value '1952-1955' to a column of data type int.
/pages/document.asp, line 14

QUESTIONS: Do I need to update the SQL database to include 2 new fields, start and end (year)? Or does the query statement contain some kind of an error? Is there a way to write the query on the .asp page to indicate that, depending on the user's selection, we want to display records from say, 2000-2099? (or 1900-1999, etc.?) OR do I need to go through and edit all 400+/- db entries so they only list ONE date in the date field (like 1995) and then just put the time span maybe in the title? (Although people here told me this page USED to work with the time span as is.)

When I examine the SQL query in the Recordset, DW MX (helpfully!) displays an error message saying "invalid column name '& startyear' " AND ALSO "invalid column name '& endyear' " . Here is SQL query statement as it currently exists:

SELECT sid,date,voices
FROM dbo.timeline_entries
WHERE date between " & startyear & " and " & endyear & "
ORDER BY date desc


Here is some of the code from the .asp page:

<%@LANGUAGE="VBSCRIPT"%>

<%
if ((Request.QueryString("start") <> "") and (Request.QueryString("end") <> "")) then
    startyear = Request.QueryString("start")
    endyear = Request.QueryString("end")

    set rs = Server.CreateObject("ADODB.Recordset")
    rs.ActiveConnection = MM_convergeCTE_STRING
    rs.Source = "SELECT sid,date,voices FROM dbo.timeline_entries where date between " & startyear & " and " & endyear & " order by date desc"
    rs.CursorType = 0
    rs.CursorLocation = 2
    rs.LockType = 3
    rs.Open()
    rs_numRows = 0

**************

Note that the line 14 referenced in the error messages returned by Firefox and Netscape refers to the
     rs.Open()
line. Very curious.

MS IE just returns the HTTP 500 Internal server error.

If you have any suggestions on this, I would greatly appreciate it. Thanks so much.

--BuddyZ
 
Old August 30th, 2006, 08:48 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Date values have to be surrounded in ' ' so your statment should be:

"SELECT sid,date,voices FROM dbo.timeline_entries where date between '" & startyear & "' and '" & endyear & "' order by date"

"The one language all programmers understand is profanity."
 
Old August 30th, 2006, 09:06 AM
Authorized User
 
Join Date: Aug 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Doug,

THANK YOU. And my boss thanks you. That worked like a charm, great when it's a simple fix. I will be taking some courses over the next 6 months in programming, asp, vbscript etc. so that should help. Maybe I will be able to give something back here sometime in the future.

HAVE A GREAT DAY!

-buddyz
 
Old August 30th, 2006, 09:46 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Your welcome, glad it worked out for you.

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Row Colours dependant on a field- FIXED Andrew.Berry ASP.NET 2.0 Basics 6 December 13th, 2007 05:59 AM
write text file with fixed field length hugoscp Classic ASP Professional 0 June 27th, 2007 06:12 AM
Error getting field names from query vbark Access VBA 1 January 23rd, 2007 09:04 PM
ADODB.Field error '800a0bcd' - FIXED buddyz Classic ASP Databases 2 October 9th, 2006 05:52 PM
Help me on Fixed Field Length data files hossrad SQL Server DTS 3 January 29th, 2005 07:50 PM





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