Saving date to datetime throws Datetime field overflow - vbscript

I am attempting to save a date and I get the error,
"[Microsoft][ODBC Driver 13 for SQL Server]Datetime field overflow. Fractional second precision exceeds the scale specified in the parameter binding."
The column I am saving is a Datetime column in sql named rowUpdateDate.
The value I am setting to the row comes from the vb datetime method Now().
This code was working until an ODBC driver was updated on the server.
rs("rowUpdateDate") = now()
rs.ActiveConnection = cn
rs.UpdateBatch adAffectAll

Due to the driver update, updating the table by using the record set no longer works. This could be due to the addition of datetime2, but unsure.
What worked was changing the code to use a SQL update statement to update the table instead of the record.
updateSQL="UPDATE contractorApplicationProcess SET "
updateSQL=updateSQL & "DMID='" & Request("DMID") & "',"
updateSQL=updateSQL & "RecruitingID='" & Request("RecruiterMembership") & "',"
updateSQL=updateSQL & "contractorID='" & Request("contrID") & "',"
updateSQL=updateSQL & "rowUpdateDate='" & now() & "',"
updateSQL=updateSQL & "rowUpdateID='" & ResourceID & "'"
updateSQL=updateSQL & " WHERE contractorApplicationProcessID='" & clng(contrApplProcessID) & "'"
cn.Execute updateSQL

Related

How to save file in vbscript with previous date

I am trying to save excel file with previous date in vbscript.
Fill has been save but date format not like 5-Jun-2019.
Please help me..
MyDateFormat = Year(now) & Right("0" & Month(Now), 2) & Right("0" & Day(now)-1, 2)
wbm.SaveAs "C:\report " & MyDateFormat & ".xlsx"
Expected Actual Result like:5-Jun-2019
date-1 gives yesterday "05.06.2019" in my case, this will not let you encounter day = 00, rest should be done by formatting

Passing a MS Access Form date into an Oracle SQL

I'm using MS Access to pull some data from an Oracle server via a pass-through query. The user is presented with a form in which they can input some variables (such as a date range). I would like the Oracle SQL to be able to pick up the two date fields from the form.
The current SQL (which doesn't work) is as follows:
SELECT a.I_LOAN_NUM, a.I_LOAN_SUB_ALLOC, c.N_EXCLV, e.I_GSL_SPNSR, e.N_GSL_SPNSR, b.D_CAL, b.C_LOAN_STAT, g.N_CNTRY
FROM SLD_LOAN_MSTR a
JOIN SLD_LOAN_CDL b on b.I_LOAN_ID = a.I_LOAN_ID
JOIN SLD_EXCLV c on c.I_EXCLV_ID = b.I_EXCLV_ID
JOIN SLD_AC d on d.I_AC_ID = b.I_AC_ID
JOIN SLD_CUST e on e.I_CUST_ID = d.I_CUST_ID
JOIN SLD_DPT_CNTRY f on f.I_DPT_ID = b.I_DPT_ID
JOIN SLD_CNTRY g on g.I_CNTRY_ID = f.I_CNTRY_ID
WHERE (b.C_LOAN_STAT = 'SETTLED' and b.D_CAL between [Forms]![Cost Allocation Form]![Start_Date] and [Forms]![Cost Allocation Form]![End_Date])
ORDER BY b.D_CAL
The above SQL works if I replace the form references with hard coded dates, so I know the SQL is generally good. Example:
WHERE (b.C_LOAN_STAT = 'SETTLED' and b.D_CAL between '01JAN2019' and '01FEB2019')
The error message being generated by the SQL states "ODBC--call failed. [Oracle][ODBC][Ora]ORA-00936: missing expression (#936)"
Both of the date fields in the Form are using the Short Date format.
I'm not sure if this makes any difference or not, but the Form has multiple tabs. From what I've seen from other examples, the Form reference doesn't need to take the tab labels into account.
Thanks
Pass-through queries are executed at the server. In your case the Oracle server doesn't recognize the [Forms]![Cost Allocation Form]![Start_Date] and [Forms]![Cost Allocation Form]![End_Date] attributes.
You could use VBA to dynamically update the query definition of the query to include the form control values. Then execute the query.
Dim strSQL As String
Dim qdf As QueryDef
strSQL = "SELECT a.I_LOAN_NUM, a.I_LOAN_SUB_ALLOC, c.N_EXCLV, e.I_GSL_SPNSR, e.N_GSL_SPNSR, b.D_CAL, b.C_LOAN_STAT, g.N_CNTRY " & _
"FROM SLD_LOAN_MSTR a " & _
"JOIN SLD_LOAN_CDL b on b.I_LOAN_ID = a.I_LOAN_ID " & _
"JOIN SLD_EXCLV c on c.I_EXCLV_ID = b.I_EXCLV_ID " & _
"JOIN SLD_AC d on d.I_AC_ID = b.I_AC_ID " & _
"JOIN SLD_CUST e on e.I_CUST_ID = d.I_CUST_ID " & _
"JOIN SLD_DPT_CNTRY f on f.I_DPT_ID = b.I_DPT_ID " & _
"JOIN SLD_CNTRY g on g.I_CNTRY_ID = f.I_CNTRY_ID " & _
"WHERE (b.C_LOAN_STAT = 'SETTLED' and b.D_CAL between '" & _
[Forms]![Cost Allocation Form]![Start_Date] & "' and '" & [Forms]![Cost Allocation Form]![End_Date] & _
"' ORDER BY b.D_CAL"
Set qdf = CurrentDb.QueryDefs("PassThroughQueryName")
qdf.SQL = strSQL
Also since your using dates, I would suggest you format your dates to the ISO format yyyy-mm-dd
in this case formatting the controls like
Format([Forms]![Cost Allocation Form]![Start_Date], "yyyy-mm-dd") & "' and '" & Format([Forms]![Cost Allocation Form]![End_Date], "yyyy-mm-dd")
Another way would be to just use VBA ADO to access the Oracle Server and retrieve the data. You would still need to build up your SQL string as mentioned here.

Time in 24 hour format in VBScript

I am trying to get the system time in 24 hour format using VBScript. I had gone through the documents and found nothing. I need to compare the system date and time with my data and need to check the differences.
WScript.Echo right("0" & hour(time),2) & ":" & right("0" & minute(time),2)
WScript.Echo FormatDateTime(time, vbShortTime)
VBScript's Date datatype is format-agnostic. You can calculate the difference between the system time and some other timestamp using the DateDiff function, as long as VBScript recognizes the format of the other timestamp. Example (calculating the difference in seconds):
>>> systime = Now
>>> WScript.Echo systime
26.11.2013 12:48:52
>>> WScript.Echo DateDiff("s", systime, "11/25/2013 23:16:52")
-48720
>>> WScript.Echo DateDiff("s", systime, "25.11.2013 23:16:52")
-48720

ASP Classic My company has a homegrown app that has issues since a move to Server 2008

We have an intranet app that basically queries a bunch of databases and arranges the data. It is written in ASP(I KNOW) and upon a move to Windows Server 2008 we have one field that no longer populates. I know the database connection is good as everything else on that page loads just fine. This leads me to believe that it is a problem with the syntax of that particular query and that since it is using TO_DATE maybe there is some difference between Server 2003 and 2008 in regards to date format.
'SQL TO PULL PROCESS GROUP
pgsql = "SELECT DISTINCT subsystem_process_group.subsystem_id, subsystem_process_group.process_group_id, "
pgsql = pgsql & "process_group.process_group_name, oncall_group_day.employee_nbr "
pgsql = pgsql & " FROM eco_admin.process_group, eco_admin.subsystem_process_group, eco_admin.oncall_group_day "
pgsql = pgsql & "WHERE ((process_group.process_group_id = subsystem_process_group.process_group_id) "
pgsql = pgsql & "AND (process_group.process_group_id = oncall_group_day.process_group_id(+)) "
pgsql = pgsql & "AND (ONCALL_GROUP_DAY.CALENDAR_DATE(+) = TO_DATE(SYSDATE)) "
pgsql = pgsql & "AND (oncall_group_day.oncall_member_role_code(+) = 'P" & hour(now) & "') "
pgsql = pgsql & "AND (subsystem_process_group.subsystem_id = " & request("id") & ")) "
function get_name(emp_nbr)
sql3 = "select LTRIM(RTRIM(INITCAP(COMMON_NAME))) COMMON_NAME, LTRIM(RTRIM(INITCAP(LAST_NAME))) last_name from (select EMPLOYEE_NBR,COMMON_NAME, LAST_NAME from hrit_admin.employee union all select CONTRACT_RESOURCE_ID, COMMON_NAME, LAST_NAME from hrit_admin.contract_resource) a where employee_nbr = a.employee_nbr and employee_nbr = " & emp_nbr
rs3.open sql3,conn
get_name = rs3("COMMON_NAME") & " " & rs3("LAST_NAME")
rs3.close
end function

get value of Checkbox in datagrid

I am working with windows application.
I have a datagrid in vb.net. Its first column is a checkbox. I want to know which checkboxes are checked and which are not.
My code is :
Dim dr As DataGridViewRow
For i = 0 To gdStudInfo.RowCount - 1
dr = gdStudInfo.Rows(i)
att = dr.Cells(0).Value.ToString()
If att.Equals("Present") Then
qry = "insert into Stu_Att_Detail values(" & id & "," & gdStudInfo.Rows(i).Cells(1).Value.ToString() & ",'" & dr.Cells(0).Value.ToString() & "')"
con.MyQuery(qry)
End If
Next
I am getting correct values for all checked check box, but it gets error when the checkbox is not checked.
What if you try this?
If Not String.IsNullOrEmpty(dr.Cells(0).Value) Then
'do stuff here
End If

Resources