I have a reservation page and a reservation table which contains reservationstart column, reservationend column and numofdays column.
I have determined the number of days between the two dates which a client will select but nothing was stored in the table when I update.
The data type of numofdays was datatime but I have changed this to int.
I used this first, to declare the start and end date:
DayPilotScheduler1.Scale = TimeScale.Manual
Dim start As New Date(Date.Today.Year, 1, 1, 12, 0, 0)
Dim [end] As Date = start.AddYears(1)
This is the code for the update:
Protected Sub DayPilotScheduler1_EventMove(ByVal sender As Object, ByVal e As DayPilot.Web.Ui.Events.EventMoveEventArgs)
Dim id_Renamed As String = e.Value
Dim start As Date = e.NewStart
Dim [end] As Date = e.NewEnd
Dim resource As String = e.NewResource
Dim message As String = Nothing
If Not dbIsFree(id_Renamed, start, [end], resource) Then
message = "The reservation cannot overlap with an existing reservation."
ElseIf e.OldEnd <= Date.Today Then
message = "This reservation cannot be changed anymore."
ElseIf e.OldStart < Date.Today Then
If e.OldResource <> e.NewResource Then
message = "The room cannot be changed anymore."
Else
message = "The reservation start cannot be changed anymore."
End If
ElseIf e.NewStart < Date.Today Then
message = "The reservation cannot be moved to the past."
Else
dbUpdateEvent(id_Renamed, start, [end], resource)
'message = "Reservation moved.";
End If
LoadResourcesAndEvents()
DayPilotScheduler1.UpdateWithMessage(message)
End Sub
Private Sub dbUpdateEvent(ByVal id As String, ByVal start As Date, ByVal [end] As Date, ByVal resource As String)
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("connectionStringLocal").ConnectionString)
con.Open()
Dim numOfDay As Integer = CInt(([end] - start).TotalDays())
Dim cmd As New SqlCommand("UPDATE [Reservation] SET ReservationStart = #start, ReservationEnd = #end, RoomId = #resource,numofday=#numofday WHERE ReservationId = #id", con)
cmd.Parameters.AddWithValue("id", id)
cmd.Parameters.AddWithValue("start", start)
cmd.Parameters.AddWithValue("end", [end])
cmd.Parameters.AddWithValue("resource", resource)
cmd.Parameters.Add("numofday", SqlDbType.Int).Value = numOfDay
cmd.ExecuteNonQuery()
End Using
End Sub
Screenshot of database table structure:
Math.floor(Math.abs(new Date(timestringone) - new Date(timestringtwo))/(1000*60*60*24))
Simply subtracting the dates returns the time in Milliseconds inbetween them. If the first time was before the second time the value is negative, so i used Math.abs to make it absolute. Then we divide trough 1000Milliseconds=1second, 60seconds=1minute, 60minutes=1hour, 24hours=1 day, and floor it to whole days. Requires two valid timestrings (timestringone and timestringtwo) to be given.
This is a javascript solution as youve included the js tag...
I am not sure about the VB.Net but you can easily accomplished it in C# using an object of Type "TimeSpan". For example: let's assume that we want to know the number of days between the start and end. values for the DateTime Type and show it in a Console window, then I may write something like:
DateTime start=DateTime.MinValue;
DateTime end=DateTime.MaxValue;
TimeSpan span=end-start;
Console.WriteLine( "There're {0} days between {1} and {2}" , span.TotalDays, start.ToString(), end.ToString() );
OP is having problems using the .Days property on the TimeSpan structure. I think this may help:
Dim numOfDay As Integer = CInt(([end] - start).TotalDays())
The output is:
365
Moving onto the use of your parameters, I think you would benefit from using .Add and specifying the data type:
cmd.Parameters.Add("#id", SqlDbType.Int).Value = id
cmd.Parameters.Add("#start", SqlDbType.Date).Value = start
cmd.Parameters.Add("#end", SqlDbType.Date).Value = [end]
cmd.Parameters.Add("#resource", SqlDbType.Int).Value = CInt(resource)
cmd.Parameters.Add("#numofday", SqlDbType.Int).Value = numOfDay
Note that you may have to change the SqlDbType. I've taken an assumption.
I would also implement Using for both the SqlConnection and SqlCommand. This for me is just good practice and the code does read better. I would also use the .Add overload for all parameters.
Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("connectionStringLocal").ConnectionString),
cmd As New SqlCommand("UPDATE [Reservation] SET ReservationStart = #start, ReservationEnd = #end, RoomId = #resource, numofday = #numofday WHERE ReservationId = #id", con)
con.Open()
cmd.Parameters.Add("#id", SqlDbType.Int).Value = id
cmd.Parameters.Add("#start", SqlDbType.Date).Value = start
cmd.Parameters.Add("#end", SqlDbType.Date).Value = [end]
cmd.Parameters.Add("#resource", SqlDbType.Int).Value = CInt(resource)
cmd.Parameters.Add("#numofday", SqlDbType.Int).Value = CInt(([end] - start).TotalDays())
Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
If rowsAffected = 0 Then
'nothing updated
Else
'something updated
End If
End Using
Related
I'm having a problem with an ASP 2005 application, the problem is that I´m calling a stored procedure in Oracle saved on a package, that procedure is very heavy (has like 1000 lines) and at the end it inserts into a table the data that it just calcutaded, then in other vb function I get the information from that table and show it on a gridview, but the 2 columns that are calculated sometimes come with value 0 and sometimes come with the values that should be. This only happens when I call the precedure from asp, when I run it from Toad it always get values on those columns... Do you have an idea of what could be happening??
This is the function I use for sending parameters:
Private Function LoadTable(ByVal tipee As String, ByVal period As String, ByRef ErrorUser As String, ByVal dateInit As String, ByVal dateEnd As String) As Boolean
Dim cmd As New OracleCommand
cmd.CommandText = "Schema.PKG.procedureA"
cmd.CommandType = CommandType.StoredProcedure
Dim Prmts(6) As OracleClient.OracleParameter
Prmts(0) = New System.Data.OracleClient.OracleParameter("ptipotrans", OracleType.VarChar)
Prmts(0).Value = tipee
Prmts(1) = New System.Data.OracleClient.OracleParameter("pperiodo", OracleType.VarChar)
Prmts(1).Value = period
Prmts(2) = New System.Data.OracleClient.OracleParameter("pfechaini", OracleType.VarChar)
If dateInit = "" Then
Prmts(2).Value = DBNull.Value
Else
Prmts(2).Value = dateInit
End If
Prmts(3) = New System.Data.OracleClient.OracleParameter("pfechafin", OracleType.VarChar)
If dateEnd = "" Then
Prmts(3).Value = DBNull.Value
Else
Prmts(3).Value = dateEnd
End If
Prmts(4) = New System.Data.OracleClient.OracleParameter("perror", OracleType.VarChar, 100)
Prmts(4).Direction = ParameterDirection.Output
cmd.Parameters.Clear()
For i As Integer = 0 To 4
cmd.Parameters.Add(Prmts(i))
Next
Dim cls_sql As New cls_ejecutaSql
Return cls_sql.exec_ens(cmd, errorUser)
End Function
And this the function I use for connecting to Oracle:
Public Function exec_ens(ByVal cmd As OracleCommand, ByRef msg As String) As Boolean
Dim lint_resul As Boolean
con.Open()
cmd.Connection = con
Try
cmd.ExecuteNonQuery()
lint_resul = True
Catch ex As Exception
msg = cmd.Parameters("perror").Value
lint_resul = False
Finally
con.Close()
End Try
Return lint_resul
End Function
I don't see anything out of the normal in those functions, and I also verified that the parameters are being sent well
enter image description hereI'm trying to validate a textbox where users will put an ID. The ID has to be numeric and at the same time compare to a valid ID in the database. When I was just validating for numeric, I didn't have any problems. But now that I have two conditions, my code doesn't work properly. Whenever I type in letters in the textbox and click a button, it gives me an error. The boolean is throwing me off lol. Below is my code:
Thank you in advance.
Protected Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
Dim dt As DataTable
Dim dr As DataRow
Dim Conn As New SqlConnection("Data Source=Computer;Initial Catalog=Catalog;Persist Security Info=True;User ID=userid;Password=password")
Dim cmd As New SqlCommand("SELECT COUNT(*) FROM [tbl] WHERE [ID]=#Value", Conn)
cmd.Parameters.Add("#Value", SqlDbType.NVarChar).Value = txtId.Text
Conn.Open()
Dim valueExistsInDB As Boolean = CBool(CInt(cmd.ExecuteScalar()) > 0)
Conn.Close()
If (IsNumeric(txtId.Text)) AndAlso valueExistsInDB = True AndAlso txtId.Text IsNot Nothing Then
dt = GetDataTable("SELECT ID, LEFT(SANZ_ID, PATINDEX('%.%', SANZ_ID) -1) AS City, CASE WHEN ST_DIR_ID = 1 THEN 'NB' WHEN ST_DIR_ID = 2 THEN 'SB' WHEN ST_DIR_ID = 3 THEN 'EB' WHEN ST_DIR_ID = 4 THEN 'WB' END AS ST_DIR, STREET_OF_TRAVEL, CROSS_STREET, (SELECT TOP 1 CASE WHEN STATUS_ID = 1 THEN 'F' WHEN STATUS_ID = 2 THEN 'P' WHEN STATUS_ID = 3 THEN 'I' WHEN STATUS_ID = 4 THEN 'N' WHEN STATUS_ID = 5 THEN 'A' END FROM tbl where dbo.tbl.ID=ID) AS STATUS FROM tbl WHERE ID=" & txtId.Text)
dr = dt.Rows(0)
labelStreet.Text = dr("street_of_travel")
labelCrossStreet.Text = dr("cross_street")
labelCity.Text = dr("city")
labelDir.Text = dr("st_dir")
labelAda.Text = dr("STATUS")
'dropdownStatus.SelectedValue=
dropdownStatus.Visible = True
txtNotes.Visible = True
btnSave.Visible = True
Else
MessageBox.Show("ID not found! Please input a valid ID.")
End If
End Sub
If ID is a numeric field then you should pass a numeric parameter not an NVarChar one
' First try to convert the input text to an integer '
' this should be done here before acting on the db '
Dim id As Integer
if Not Int32.TryParse(txtId.Text, id) Then
MessageBox.Show("Error, not a valid number")
return
End If
Dim cmdText = "SELECT COUNT(*) FROM [tbl] WHERE [ID]=#Value"
Using Conn = New SqlConnection(....)
Using cmd As New SqlCommand(cmdText, Conn)
cmd.Parameters.Add("#Value", SqlDbType.Int).Value = id
Conn.Open()
Dim valueExistsInDB = CBool(CInt(cmd.ExecuteScalar()) > 0)
' At this point you don't need anymore to check if the input value'
' is numeric and your if is more simple.....'
if valueExistsInDB Then
......
... continue with your code ....
Else
MessageBox.Show("ID not found! Please input a valid ID.")
End if
End Using
End Using
I'm creating multiple choice question system. So far i create these 4 tables and 1 view.
The tables are tblQuestion, tblAnswer, tblQuiz, tblResult and tblResultDetail. tblQuestion is to store the questions, tblAnswer to store the answers of the question,tblResult is to record for every user that answers the quiz, and store the users answers in TblResultDetails.
Based on the code below, the data is read from view. I use 1 , 2 , 3, 4 as it is the column name of the view. I did this to randomize the answers.
Sub soalan()
conn.Open()
Dim myArr(3) As String
Dim cmd As New SqlCommand("Select * From view_Soalan Where QuestionID=#IdSoalan", conn)
cmd.Parameters.AddWithValue("#IdSoalan", Counter)
Dim dr1 As SqlDataReader
dr1 = cmd.ExecuteReader
If dr1.Read() Then
Me.lblSoalan.Text = dr1("QuestionTxt")
Me.RadioButton1.Text = dr1("1")
myArr(0) = dr1("1")
Me.RadioButton2.Text = dr1("2")
myArr(1) = dr1("2")
Me.RadioButton3.Text = dr1("3")
myArr(2) = dr1("3")
Me.RadioButton4.Text = dr1("4")
myArr(3) = dr1("4")
Dim answerId As String
If Me.RadioButton1.Checked = True Then
answerId = dr1("1")
ElseIf Me.RadioButton2.Checked = True Then
answerId = dr1("2")
ElseIf Me.RadioButton3.Checked = True Then
answerId = dr1("3")
ElseIf Me.RadioButton4.Checked = True Then
answerId = dr1("4")
End If
'Dim jawapan As Integer = CInt(answerId)
Session("jaw") = answerId
Else
conn.Close()
Counter += 1
soalan()
End If
conn.Close()
End Sub
Sub bersih()
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
soalan()
End Sub
Sub masuk()
conn.Open()
Dim cmdGetId As New SqlCommand("Select MAX(ResultId) From TblResult", conn)
cmdGetId.ExecuteNonQuery()
Dim drBaca As SqlDataReader
drBaca = cmdGetId.ExecuteReader
While drBaca.Read
Dim maxID As Integer = drBaca(0)
Session("maximum") = maxID
End While
conn.Close()
conn.Open()
Dim cmdInsert As New SqlCommand("Insert into TblResultDetail (ResultDetail_Result_Id,ResultDetail_Answer_Id) values ('" & Session("maximum") & "','" & Session("jaw") & "')", conn)
cmdInsert.ExecuteNonQuery()
conn.Close()
End Sub
End Class
I got error
Conversion failed when converting the varchar value 'table' to data
type int.
at the cmdInsert command. I know that i cant insert the session("jaw") into table directly. So how to replace it?
In your query you are quoting integers:
... values ('" & Session("maximum") & "','"
Simply remove the quotes. Also you should user Parameters instead to prevent SQL Injection.
I.e.
Dim cmdInsert As New SqlCommand("Insert into TblResultDetail (ResultDetail_Result_Id,ResultDetail_Answer_Id) values (#max, #jaw)", conn)
cmdInsert.Parameters.AddWithValue("#max", Session("maximum"))
cmdInsert.Parameters.AddWithValue("#jaw", Session("jaw"))
I think that you have store in some of this fields a wrong value.
use this
Public Module MyExtensions
<System.Runtime.CompilerServices.Extension()> _
Public Function IsInteger(ByVal value As String) As Boolean
If String.IsNullOrEmpty(value) Then
Return False
Else
Return Integer.TryParse(value, Nothing)
End If
End Function
<System.Runtime.CompilerServices.Extension()> _
Public Function ToInteger(ByVal value As String) As Integer
If value.IsInteger() Then
Return Integer.Parse(value)
Else
Return 0
End If
End Function
End Module
and then
value.ToInteger() <-- returns 0 if it is not an integer
There is another error in your code. You should use ExecuteScalar instead of ExecuteNonQuery in the query that starts with
"Select MAX(ResultId)...."
Dim cmdGetId As New SqlCommand("Select MAX(ResultId) From TblResult", conn)
Dim maxID As Integer= cmdGetId.ExecuteScalar
Session("maximum") = maxID
ExecuteScalar is typically used when your query returns a single value.
ExecuteNonQuery is typically used for SQL statements without results (UPDATE, INSERT, etc.).
Refer this
I have searched high and low to no avail, and this is last step before completing my project so please help! Thanks in advance!
The user will select an entry in a gridview, which then redirects them to a form that is populated with the data from the selected row (thus making the gridview editable in a more user friendly way). Null values are accepted by the DB and I would like to show null date values as blank (or " ") in the corresponding text boxes. Instead I get the error:
Conversion from type 'DBNull' to type 'Date' is not valid.
Here is my code:
'preceded by connection code
Dim sqlcmd As String = "SELECT * from Master WHERE RecNum = #recnum"
'Dim sqlCmd As New OleDb.OleDbCommand("SELECT * from Master WHERE RecNum = #recnum", connection)
Dim FileCommand3 As New OleDb.OleDbCommand(sqlcmd, connection)
FileCommand3.Parameters.AddWithValue("#recnum", user)
Dim Reader3 As OleDb.OleDbDataReader = FileCommand3.ExecuteReader()
If Reader3.Read Then
stock = myCStr(Reader3("StockNum"))
make = myCStr(Reader3("Make"))
color = myCStr(Reader3("Color"))
stockin = myCStr(Reader3("Stockin"))
ucistart = myCStr(Reader3("UCIStartDate"))
repairs = Reader3("Repairs")
tires = Reader3("tiresneeded")
onlot = Reader3("onlot")
sold = Reader3("sold")
year = myCStr(Reader3("year"))
model = myCStr(Reader3("model"))
location = Reader3("location")
srvcRO = myCStr(Reader3("svcROnum"))
ucicompldate = myCStr(Reader3("uciestcompletedate"))
collRO = myCStr(Reader3("collisionROnum"))
other = myCStr(Reader3("other"))
offprop = Reader3("offProperty")
detail = (Reader3("detail")
End If
connection.Close()
SoldCheckBX.Checked = sold
DetailTXTbox.Text = detail
'etc, etc
End Sub
I used the function mycstr to fix the dbnull to string error but it does not seem as simple to adapt to "date" data type
Function myCStr(ByVal test As Object) As String
If isdbnull(test) Then
Return ("")
Else
Return CStr(test)
End If
End Function
try this when you read the values from the reader with all your dates, this will first test to see if the date is dbnull, if it is then it will assign a nothing value and you should get your desired empty cell, otherwise it will show the date:
ucistart = IIf(reader3("UCIStartDate") Is DBNull.Value, Nothing, reader3("UCIStartDate"))
Have you tried using the Convert.IsDBNull function?
Here is the official documentation.
I am developing an ASPX web page to return results from two SQL stored procs via VB. When I execute these two stored procs, they both return valid data. But for some reason, when I run this report it doesn't return any errors, however, it doesn't return any records/data either!
Also, I can't debug it for some reason, although I can set breakpoints! This is using VS 2008, but I think reason I can't debug is I believe this is a limited version that just works for SSRS and SSIS.
Here is an excerpt of my code:
<HTML>
<SCRIPT LANGUAGE="VB" RUNAT="Server">
Sub Page_Load(Sender as Object, E as EventArgs)
If Not IsPostback Then
Dim TheMonthDate As Date = DateAdd(DateInterval.Month, -1, Today)
calStartDate.SelectedDate = CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy")
calEndDate.SelectedDate = GlobalFunctions.GlobalF.MonthLastDate(CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy"))
Dim arrLevel as New ArrayList()
arrLevel.Add("All")
arrLevel.Add("Inquiries")
arrLevel.Add("All Complaints")
arrLevel.Add("Elevated Complaints")
arrLevel.Add("Non-Elevated Complaints")
dLevel.DataSource = arrLevel
dLevel.DataBind()
dLevel.selectedvalue = "All Complaints"
End If
Main
End Sub
Sub Main()
'------------------------- Query database and get arrays for the chart and bind query results to datagrid ----------------------------------------
Dim FirstMonthDate as date = calStartDate.SelectedDate
Dim LastMonthDate as date = calEndDate.SelectedDate
Dim TheLevel As Integer
Dim TitleLevel as String
Select Case dLevel.SelectedValue
Case "All"
TheLevel = 5
TitleLevel = "Inquiries and Complaints"
Case "Inquiries"
TheLevel = 0
TitleLevel = "Inquiries"
Case "All Complaints"
TheLevel = 3
TitleLevel = "All Complaints"
Case "Elevated Complaints"
TheLevel = 2
TitleLevel = "Elevated Complaints"
Case "Non-Elevated Complaints"
TheLevel = 1
TitleLevel = "Non-Elevated Complaints"
End Select
Dim DSPageData as new System.Data.DataSet
DSPageData = GlobalFunctions.GlobalF.GetComplaintTrending2(FirstMonthDate, LastMonthDate, TheLevel)
...
Dim DSDetails As New System.Data.DataSet
DSDetails = GlobalFunctions.GlobalF.GetComplaintTrendingDetails2(FirstMonthDate, LastMonthDate, TheLevel)
dgTable.DataSource = DSDetails
dgTable.DataBind()
Where in my Global.vb file I have:
'Added by Ryan on 4/17/11
Public Shared Function GetComplaintTrending2(ByVal FirstMonth As DateTime, ByVal LastMonth As DateTime, ByVal rowLevel As Integer) As DataSet
Dim DSPageData As New System.Data.DataSet
Dim param(2) As SqlClient.SqlParameter
param(0) = New SqlParameter("#FirstMonthDate", SqlDbType.DateTime)
param(0).Value = FirstMonth
param(1) = New SqlParameter("#LastMonthDate", SqlDbType.DateTime)
param(1).Value = LastMonth
param(2) = New SqlParameter("#TheLevel", SqlDbType.Int)
param(2).Value = rowLevel
''# A Using block will ensure the .Dispose() method is called for these variables, even if an exception is thrown
''# This is IMPORTANT - not disposing your connections properly can result in an unrespsonsive database
Using conn As New SQLConnection(ConfigurationSettings.AppSettings("AMDMetricsDevConnectionString")), _
cmd As New SQLCommand("ComplaintTrending2", conn), _
da As New SQLDataAdapter(cmd)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddRange(param)
da.Fill(DSPageData)
End Using
Return DSPageData
End Function
'Added by Ryan on 4/17/11
Public Shared Function GetComplaintTrendingDetails2(ByVal FirstMonth As DateTime, ByVal LastMonth As DateTime, ByVal rowLevel As Integer) As DataSet
Dim DSPageData As New System.Data.DataSet
Dim param(2) As SqlClient.SqlParameter
param(0) = New SqlParameter("#FirstMonthDate", SqlDbType.DateTime)
param(0).Value = FirstMonth
param(1) = New SqlParameter("#LastMonthDate", SqlDbType.DateTime)
param(1).Value = LastMonth
param(2) = New SqlParameter("#TheLevel", SqlDbType.Int)
param(2).Value = rowLevel
''# A Using block will ensure the .Dispose() method is called for these variables, even if an exception is thrown
''# This is IMPORTANT - not disposing your connections properly can result in an unrespsonsive database
Using conn As New SQLConnection(ConfigurationSettings.AppSettings("AMDMetricsDevConnectionString")), _
cmd As New SQLCommand("ComplaintTrendingDetails2", conn), _
da As New SQLDataAdapter(cmd)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddRange(param)
da.Fill(DSPageData)
End Using
Return DSPageData
End Function
And these stored procs are defined as:
CREATE PROCEDURE [dbo].[ComplaintTrendingDetails2]
--DECLARE
#FirstMonthDate DATETIME,
#LastMonthDate DATETIME,
#TheLevel INT
AS
SET NOCOUNT ON;
--ComplaintTrendingDetails2 '2/1/11', '2/28/11 23:59:59', 2
--SET #FirstMonthDate = '2/1/11'
--SET #LastMonthDate = '2/28/11 23:59:59'
--SET #TheLevel = '2'
SELECT DISTINCT
A.QXP_EXCEPTION_NO, A.[LEVEL], A.pRE,
A.QXP_REPORT_DATE, A.CLOSE_DATE, A.EPA_PRD_NAME,
A.EPA_PRD_CODE, A.EPL_LOT_NUMBER,
A.QXP_SHORT_DESC, A.QXP_DESCRIPTION,
A.QXP_RESOLUTION_DESC, A.CXP_CLIENT_NAME, A.Country,
C.PRODUCT, C.PRODUCT_GROUP, C.PRODUCT_ORG_UNIT,
B.DOC_DOCUMENT_NO, A.TICKET_NUM, A.CENTER_NUM,
A.COUNTRY_CODE, A.QXP_ID, B.IRF_QEI_ID
FROM ALL_COMPLAINTS A LEFT OUTER JOIN
SMARTSOLVE.V_QXP_ISSUE_REF B ON A.QXP_ID = B.IRF_QXP_ID LEFT OUTER JOIN
MANUAL.PRODUCTS C ON A.EPA_PRD_CODE = C.LIST_NUMBER
LEFT OUTER JOIN SMARTSOLVE.V_CXP_CUSTOMER_PXP D ON A.QXP_ID = D.QXP_ID
WHERE A.QXP_REPORT_DATE >= #FirstMonthDate AND A.QXP_REPORT_DATE <= #LastMonthDate
AND (A.QXP_SHORT_DESC <> 'Design Control') AND LEVEL = #TheLevel
AND (D.QXP_EXCEPTION_TYPE <> 'Non-Diagnostic' OR D.QXP_EXCEPTION_TYPE IS NULL)
ORDER BY 4
and
--ALTER PROCEDURE [dbo].[ComplaintTrending2]
DECLARE
#FirstMonthDate DATETIME,
#LastMonthDate DATETIME,
#TheLevel INT
--AS
-- SET NOCOUNT ON;
--ComplaintTrending2 '2/1/11', '2/28/11 23:59:59', 2
SET #FirstMonthDate = '2/1/11'
SET #LastMonthDate = '2/28/11 23:59:59'
SET #TheLevel = '2'
SELECT
CASE ISNULL(PRODUCT_GROUP, '') WHEN '' THEN 'Unspecified' ELSE PRODUCT_GROUP END AS PRODUCT_GROUP,
COUNT(DISTINCT A.QXP_EXCEPTION_NO) AS CountOfTickets
FROM ALL_COMPLAINTS a
LEFT OUTER JOIN MANUAL.PRODUCTS b ON a.EPA_PRD_CODE = b.LIST_NUMBER
LEFT OUTER JOIN SMARTSOLVE.V_CXP_CUSTOMER_PXP c ON a.QXP_ID = c.QXP_ID
WHERE a.QXP_REPORT_DATE >= #FirstMonthDate AND a.QXP_REPORT_DATE <= #LastMonthDate
AND (a.QXP_SHORT_DESC <> 'Design Control') AND LEVEL = #TheLevel
AND (c.QXP_EXCEPTION_TYPE <> 'Non-Diagnostic' OR c.QXP_EXCEPTION_TYPE IS NULL)
GROUP BY PRODUCT_GROUP
ORDER BY COUNT(DISTINCT a.QXP_EXCEPTION_NO) DESC
Could the problem be due to the fact that this web page uses the same SQL connection for both stored procs? The first proc should be returned initially, and the second proc after this screen. So I don't need both stored procs information simultaneously, so I would think I could reuse the same SQL connection.
OK, I found where the problem is located. If I just comment out the Level statement in the Where clause, it does return data. So only thing I changed was that one line in my SQL code and it works. This means missing data must be due to datatype incompatibility, no? What is the problem?
I think the problem is your code does not even compile. Looking at the posted page right at the start we see this:
End If
Main
End Sub
This is not valid VB. You are running an old version of your code. This is also why you can't debug it. You don't have the current one to set break points on.