473,387 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VB / SQL Query problem

I built a ticket system a while back but I never could get the queries quite
right. My queries work as long as I don't use a date range. Here is the code
I use for the query portion (the relevant part):

If ddlReportType.SelectedValue = "Everything" And
ddlQueryTechnician.SelectedValue = "Select All" Then
strSQLCount = "SELECT COUNT(*) FROM TTickets WHERE dtemp
BETWEEN CONVERT(DATETIME, " & _
"'" & bd & "', 110) AND CONVERT(DATETIME,
'" & ed & " 23:59:59', 110)"

strSQL = "SELECT * FROM TTickets WHERE dtemp BETWEEN
CONVERT(DATETIME, '" & bd & "', 110) " & _
"AND CONVERT(DATETIME, '" & ed & " 23:59:59',
110)"

strSQL1 = "SELECT * FROM TNotes"

ElseIf ddlReportType.SelectedValue = "Everything" Then
strSQLCount = "SELECT COUNT(*) FROM TTickets WHERE
assign='" & ddlQueryTechnician.SelectedValue & "' " & _
"AND dtemp BETWEEN CONVERT(DATETIME, '" &
bd & "', 110) AND CONVERT(DATETIME, '" & _
ed & " 23:59:59', 110)"

strSQL = "SELECT * FROM TTickets WHERE assign='" &
ddlQueryTechnician.SelectedValue & "'" & _
" AND dtemp BETWEEN CONVERT(DATETIME, '" & bd &
"', 110) AND CONVERT(DATETIME, '" & _
ed & " 23:59:59', 110) ORDER BY prioritynumber"

strSQL1 = "SELECT * FROM TNotes WHERE FK IN(SELECT PK
FROM TTickets WHERE assign='" & _
ddlQueryTechnician.SelectedValue & "')"

ElseIf ddlQueryTechnician.SelectedValue = "Select All" Then
strSQLCount = "SELECT COUNT(*) FROM TTickets WHERE " &
ddlReportType.SelectedValue & _
" AND dtemp BETWEEN CONVERT(DATETIME, " &
_
"'" & bd & "', 110) AND CONVERT(DATETIME,
'" & ed & " 23:59:59', 110)"

strSQL = "SELECT * FROM TTickets WHERE " &
ddlReportType.SelectedValue & _
" AND dtemp BETWEEN CONVERT(DATETIME,'" & bd &
"', 110) AND CONVERT(DATETIME, '" & _
ed & " 23:59:59', 110) ORDER BY prioritynumber"

strSQL1 = "SELECT * FROM TNotes WHERE FK IN(SELECT PK
FROM TTickets WHERE " & _
ddlReportType.SelectedValue & ")"
Else
strSQLCount = "SELECT COUNT(*) FROM TTickets WHERE " &
ddlReportType.SelectedValue & " AND assign='" & _
ddlQueryTechnician.SelectedValue & "' AND dtemp
BETWEEN CONVERT(DATETIME, " & _
"'" & bd & "', 110) AND CONVERT(DATETIME,
'" & ed & " 23:59:59', 110)"

strSQL = "SELECT * FROM TTickets WHERE " &
ddlReportType.SelectedValue & " AND assign='" & _
ddlQueryTechnician.SelectedValue & "' AND dtemp
BETWEEN CONVERT(DATETIME, " & _
"'" & bd & "', 110) AND CONVERT(DATETIME,
'" & ed & " 23:59:59', 110) ORDER BY prioritynumber"

strSQL1 = "SELECT * FROM TNotes WHERE FK IN(SELECT PK
FROM TTickets WHERE " & _
ddlReportType.SelectedValue & ")"
End If

I can do queries ok as long as I don't use date ranges (I have the same SQL
statements that don't use the date text fields). But, if I use dates, I get
the following error:

This constraint cannot be enabled as not all values have corresponding
parent values.

The Database back end is SQL2000 with two tables (TTickets and TNotes). The
TNotes is for us IT Staff to post a note to a ticket, and is related via
foreign key to the primary key of TTickets.

Any ideas how I would be able to do queries using a date range?

TIA,
Jim
Dec 13 '05 #1
0 1084

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
11
by: Andy_Khosravi | last post by:
My problem: I'm having trouble with a query taking much too long to run; a query without any criteria evaluating only 650 records takes over 300 seconds to run (over the network. On local drive...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.