Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date field in SQL Server 2000

Status
Not open for further replies.

TazzMann

Programmer
Jul 25, 2001
79
US
I have recently started working for a company that in someone's infinite wisdom decided to name a column in MSSQL Server 2000 as the reserved keyword 'date'.

I am trying to pull some data out of a table that the only unique field is this date field. I have tried the below code, but it does not return any records. I have tried the same query with other fields and it all works good. The query with the date field is the only one that causes problems. Anyone have any ideas?

my $SQL = "Select DistinctSessions from $database_FMJtable WHERE ([Date]='05/24/04')";
print "$SQL\n";
my $FMJsth = $dbh->prepare($SQL) or warn "Cannot prepare SQL statement: $dbi::errstr\n";
$FMJsth->execute or warn "Cannot execute SQL statement: $dbi::errstr\n";
while (@FMJTempArray = $FMJsth->fetchrow_array()){
print "$FMJTempArray[0]\n";
}

The idea is that I am going to be looping through and putting dates in to pull out the one field. The results I am pushing to an array so that I may sum them all later to get a final number. The results from this query should return just one record.

Thanks in advance.

Tazzmann
 
You need the "where" parameter in the execute statement:

Code:
my $SQL = "Select DistinctSessions from $database_FMJtable WHERE ([COLOR=red][Date]='05/24/04')[/color]";

$FMJsth->execute([COLOR=red]needs to be here also[/color]) or warn "Cannot execute SQL statement: $dbi::errstr\n";

The parameter would best be in the form of a variable.

There's always a better way. The fun is trying to find it!
 
I have the whole SQL statement in the Execute statement. Does that not include the Where clause? It should. According to trace it is prepared just fine and executed just fine, just no records returned even though I know that that date exists in the database and Query Analyser uses the exact form of the SQL statement and returns the record just fine.

Tazzmann
 
Nevermind, I feel retarded! I was looking at one server through Query Analyzer and a different server through my script. The one that my script was pointing to doesn't have any recent data, thus returning zero rows which it should.

'Cause I'm a Blonde..... (NOT!)

Tazzmann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top