Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 15th, 2003, 06:26 AM
Jon Jon is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: London
Posts: 6 Jon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 13 sec
Reputation Power: 0
Question Help with datepart in SQL/ASP

Can you use datepart in an SQL query within an ASP page. The following code gives the following error when I try and use the record set

Error Type:
ADODB.Field (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

MS SQL:

sqlstr = "select userid, count(investigationtype) as numof " &_

"FROM tblitInvestigation WHERE (closedate is null or datepart(ww,closedate) >= " & qrywk & " and datepart(yyyy,closedate) = " & qryyr & ") and (datepart(ww,opendate) < " & qrywk & " and datepart(yyyy,opendate) = " & qryyr & ") AND userid ='" & rsuser("userid") & "' and branch like '" & request.form("lstbranch") & "' group by userid"


Many thanks in advance for any advice.

Cheers,

Jon

Reply With Quote
  #2  
Old October 15th, 2003, 11:07 AM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Well, so far it's correct. DatePart can be used this way, of course. But what about your query? Did you manage to execute it elsewhere? It looks very restrictive and maybe it just has no result set.

This piece may fail as well:
like '" & request.form("lstbranch") & "' ...
may be better this way:
like '" & request.form("lstbranch") & "%' ...

Reply With Quote
  #3  
Old October 16th, 2003, 11:29 AM
Jon Jon is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: London
Posts: 6 Jon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 13 sec
Reputation Power: 0
Thanks for your help,

I have made a few changes to the query and everything is working fine now. You were right; when I tested the query in SQL Query Analyzer it did not return any results.

Cheers,

Jon

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Help with datepart in SQL/ASP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT