Laravel 8 and SQL Server: problem with timestamp - laravel

Hello everyone and happy new year,
I'm converting my project to use SQL Server instead of MySQL and I'm struggling with the problem of managing timestamps.
In the project, I have this code:
Customers::whereBetween('created_at', [Carbon::now()->subDays('7'), Carbon::now()])->count();
which gives me back the number of new customers registered in the last 7 days.
Using MySQL no problem whatsoever while with SQL Server I get this error:
Converting an nvarchar data type to datetime resulted in a value
outside of the allowable range.
despite in my model, I have set
public function getDateFormat()
{
return 'Y-m-d H: i: s.v';
}
to get the values in milliseconds.
What did I forget to set up?

The error tells you that a conversion failed. Possible reasons:
The date does not exist
If you get February 30th as the input, it will fail.
Input not complying to the format in use
To detect whether this is the problem, you will need to find out what the generated SQL is and find out which value caused this problem. After carefully studying the conversion you should be able to determine what the problem and solution is.

Related

Can't get WORKDAY function to work with a COUNTIF

Trying to work on a system at work that will tell how many error codes were registered by a particular machine on the previous workday. This spreadsheet will need to be able to select only the errors generated on the previous date as this will become a rolling list of data generated across a wide time span. Currently working with the formula
=TODAY(),-1,B2:B17)
where the last array is some shutdown days I've put in to generate a global variable "Yesterday" and trying to use the formula
=COUNTIF(Table1[DateOnly],"="&Yesterday)
to gather the number of records that occurred yesterday.
Can anyone tell me where I'm going wrong?
Found that the issue was when I tried to convert the timestamp in mm/dd/yy hh:mm:ss format to mm/dd/yy and didn't realize that the other information was still hiding in there and confusing the formula. One of my coworkers recommended the use of a ROUNDDOWN function in the use of =ROUNDDOWN(argument,0) to get rid of the time information and just leave me with date.

VBA ACE issue with Oracle Decimal

We use VBA to retrieve data from an Oracle database using the Microsoft.ACE.OLEDB.12.0 provider.
We have used this method without issue for a long time, but we have encountered a problem with a specific query of data from a specific table.
When running it under VBA, we get "Run-Time error '1004': Application-defined or object-defined error. However investigating further, we find the following:
The queries we run are dynamically generated, and how we handle them is to read the results into a variant array, then output that array into Excel. When we step-through our particular query, we find that one specific database field is "blank": The locals window shows the value to be completely blank: it is not an empty string, it is not a null, it is not zero. VarType() shows it to be a decimal data type, and yet it is empty.
I can't seem to prevent this error from locking-out:
On Error Resume Next
...still breaks.
if (isEmpty(theValue)) then
...doesn't catch it, because it is not empty
if (theValue is nothing) then
...doesn't catch it because it is not an object
etc.
We used the SQL in the a .NET application, and got a more informative error:
Decimal's scale value must be between 0 and 28, inclusive. Parameter name: Scale
So: I see this as two issues:
1.) In VBA, how do I trap the variant datatype value-that-is-not-empty-or-null, and;
2.) How do I resolve the Oracle Decimal problem?
For #2, I see from the Oracle decimal data type, it can support precision of up to 31 places, and I assume that the provider I am using can only support 28. I guess I need to Cast it to a smaller type in the query.
Any other thoughts?

Cannot identify the origin of an error - hypothesis : decimal format conflicts

While executing a DB2 (V8) Stored Procedure, I get the following error :
SQL0304N A value cannot be assigned to a host variable because the value is
not within the range of the host variable's data type. SQLSTATE=22003
I did not set any kind of tracing or specific error handling and as the error only occurs in our client's validation environment that I'm not allowed to play with, I do not have many options but analyze my code again.
Here is the result of my current analysis. Google is not much of a help...
My "10 pages" procedure creates a CURSOR over a set of data, goes though it and computes values for each element to be inserted it in a table.
I have checked (hopefully) all my variables types versus data types used to fill them and versus the data types of the target table and I do not see any conflict there.
Since there are a lot of decimal numbers, multiplications and additions, my only hypothesis is that a computed value becomes too large for a defined variable. Could anyone confirm that would be the "correct error" ? And would it also apply if the number of digits after the decimal point generated by computing is greater than allowed by the targeted variable type (eg. 100000.123 in decimal(6,2)) ?
I also tried to find a way to debug db2 pl sql through a client but I did not find any solution. If you have any suggestion...
Many thanks in advance for any clue :)
I answer myself...
First, my last question => I did not find any way to debug db2 pl sql through a client (with DB2 V8 at least).
After I was authorized to work on our integration client's environment, I could confirm my hypothesis was right. The variable format receiving the multiplication was sometimes too small (decimal(10,2)) for the computed result.
The solution adopted was to change the variable format to decimal(15,2) and since the final value to insert still had to be decimal(10,2) upon client's requirements, we validated the following with our client :
1-Check the variable value :
if (myval > 9999999,99)
then
set myval = 9999999,99;
end if;
=> "back to decimal(10,2) requirement"
2-Get back to decimal(10,2) at insert :
This last bit of code also solves the issue when there are too many digits after the decimal point. That was causing an error as well at insert time
insert into mytable values (
... ,
CAST(myval AS DECIMAL( 12 , 2 )),
...
)

Error tyring to add a parameter in MS Visual Studio

I am trying to create a report in MS Visual Studio and use the DateClosed as a parameter so that a user can select on 'DateClosed'. The error I am getting says:
Error Message: Conversion failed when converting date and/or time from character string.
The select satement is below is based on a view that I had to convert a string (DateClosed) to a datatime data type.
SELECT GrantNumber, GrantAmount, GrantDate, NatureOfGrant, SpecialInstructions, FullName, GMP, GrantType, Name, DateClosed
FROM V_WSF_GrantMakingPartnersGrants
ORDER BY DateClosed DESC
I am really confused because the 'ClosedDate' above is returning the value as a datetime data type. I can't cast it again, because it already sees it as a date. This is making no sense to me.
Can anyone tell me how to add the parameter into MS Visual Studio?
It's not clear where you are getting the data from - SQL Server or Oracle? So you want to pass the date? Ie, you enter 02/02/2012 and then click to generate report?
If you are passing to Oracle, you might have to use the sql function TO_DATE(xxxx). The same thing may apply to SQL Server but that is not an area I'm not familiar with. Therefore:
..order by DateClosed may have to read like this:
to_date(DateClosed, 'yyyy/mm/dd')
The 2nd parameter - must match the date format that you are sending in...
I hope this helps...
I think you should use the dateTime.formate to specify the format type on the dataBase..
like "YYYY-MM-dd". make sure the format is the same date format you are using on your DataBase string date.
I think this will solve your problem.

Convert big int VBA

Im having to edit code in very old classic asp.
Im comparing two values.
I am getting an error saying Type mismatch
This is where it occurs:
if oRsDropDown(id_col) = variable then
the drop down is created form a sql execution
I think the issue may be that the ID column in the db being compared is a big int?
Without knowing the type that oRsDropDown returns, does it work with is?
if oRsDropDown(id_col) is variable then

Resources