If error on Access query - ms-access-2007

Hi I am doing a query in MS Access that is the following:
Tenure_days: DateSerial(Year(Date()),Month(Date()),11)-DateSerial(Mid([AHT_Tenure].[ABAY Start Date],1,4),Mid([AHT_Tenure].[ABAY Start Date],6,2),Mid([AHT_Tenure].[ABAY Start Date],9,2))
In some records is get #Error when [AHT_Tenure].[ABAY Start Date] is empty, so how do I edit the above query so that when Tenure_days = #Error to put 120 ?

The problem is because the field is empty, you need to test if the field is empty first. Try this,
Tenure_days: IIF(Len([AHT_Tenure].[ABAY Start Date] & "") = 0, 120, DateSerial(Year(Date()),Month(Date()),11) - DateSerial(Mid([AHT_Tenure].[ABAY Start Date],1,4),Mid([AHT_Tenure].[ABAY Start Date],6,2),Mid([AHT_Tenure].[ABAY Start Date],9,2)))
You first using an Immediate IF, see if the field you are using the Mid function to is empty or not. If it is empty you are giving 120 straight away. If not, you are performing the operation. I hope this helps.

Related

npgsql executescalar() allways returns nothing

I'm using npgsql as a nuget package in visual studio 2017 with visual basic.
Various commands do work very well but an ExecuteScalar allways returns 'nothing' although it should give a result.
The command looks like this:
Dim ser As Integer
Dim find = New NpgsqlCommand("SELECT serial from dbo.foreigncode WHERE code = '#code';", conn)
Dim fcode = New NpgsqlParameter("code", NpgsqlTypes.NpgsqlDbType.Varchar)
find.Parameters.Add(fcode)
find.Prepare()
fcode.Value = "XYZ"
ser = find.ExecuteScalar() ==> nothing
When the command string is copied as a value during debugging and pasted into the query tool of PGADMIN it delivers the correct result. The row is definitely there.
Different Commands executed with ExecuteNonQuery() work well, including ones performing UPDATE statements on the row in question.
When I look into the properties of the parameter fcode immediately before the ExecuteScalar it shows 'fcode.DataTypeName' caused an exception 'System.NotImplementedException'.
If I change my prepared statement to "SELECT #code" and set the value of the parameter to an arbitrary value just this value is returned. There is no access to the table taking place because the table name is not part of the SELECT in this case. If I remove the WHERE CLAUSE in the SELECT and just select one column, I would also expect that something has to be returned. But again it is nothing.
Yes there is a column named serial. It is of type bigint and can not contain NULL.
A Query shows that there is no single row that contains NULL in any column.
Latest findings:
I queried a different table where the search column and the result column happen to have the same datatype. It works, so syntax, passing of parameter, prepare etc. seems to work in principal.
The System.NotImplementedException in the DataTypeName property of the parameter occurs as well but it works anyway.
I rebuilt the index of the table in question. No change.
Still: when I copy/paste the CommandText and execute it in PGAdmin it shows the correct result.
Modifying the Command and using plain text there without parameter and without prepare still does yield nothing. The plain text CommandText was copy/pasted from PGAdmin where it was successfully executed before.
Very strange.
Reverting search column and result column also gives nothing as a result.
Please try these two alternatives and post back your results:
' Alternative 1: fetch the entire row, see what's returned
Dim dr = find.ExecuteReader()
While (dr.Read())
Console.Write("{0}\t{1} \n", dr[0], dr[1])
End While
' Alternative 2: Check if "ExecuteScalar()" returns something other than an int
Dim result = find.ExecuteScalar()
... and (I just noticed Honeyboy Wilson's response!) ...
Fix your syntax:
' Try this first: remove the single quotes around "#code"!
Dim find = New NpgsqlCommand("SELECT serial from dbo.foreigncode WHERE code = #code;", conn)
Update 1
Please try this:
Dim find = New NpgsqlCommand("SELECT * from dbo.foreigncode;", conn)
Q: Does this return anything?
Dim dr = find.ExecuteReader()
While (dr.Read())
Console.Write("{0}\t{1} \n", dr[0], dr[1])
End While
Q: Does this?
Dim result = find.ExecuteScalar()
Q: Do you happen to have a column named "serial"? What is it's data type? Is it non-null for the row(s) with 'XYZ'?
Please update your original post with this information.
Update 2
You seem to be doing ":everything right":
You've confirmed that you can connect,
You've confirmed that non-query updates to the same table work (with npgsql),
You've confirmed that the SQL queries themselves are valid (by copying/pasting the same SQL into PGAdmin and getting valid results).
As Shay Rojansky said, "System.NotImplementedException in the DataTypeName property" is a known issue stepping through the debugger. It has nothing to do with your problem: https://github.com/npgsql/npgsql/issues/2520
SUGGESTIONS (I'm grasping at straws)::
Double-check "permissions" on your database and your table.
Consider installing a different version of npgsql.
Be sure your code is detecting any/all error returns and exceptions (it sounds like you're probably already doing this, but it never hurts to ask)
... and ...
Enable verbose logging, both client- and server-side:
https://www.npgsql.org/doc/logging.html
https://www.postgresql.org/docs/9.0/runtime-config-logging.html
... Finally ...
Q: Can you make ANY query, from ANY table, using ANY query method (ExecuteReader(), ExecuteScalar(), ... ANYTHING) from your npgsql/.Net client AT ALL?
I finally found it. It's often the small things that can have a big impact.
When the value was assigned to the parameter a substring index was incorect.
Now it works perfectly.
Thanks to everybody who spent his time on this.

WHERE Condition in the Kentico repeater

I have a list of events that are shown on "Events" page using a repeater. Each event is a page type and has a field "EventStartDateTime". I want to show only those events where the event start date is >= today. For now in the WHERE field in repeater,i am using the following condition:
(EventStartDateTime >= '{% DateTime.Now #%}') OR (EventStartDateTime = '')
But no data is visible on the page. So is it right ?
Any help will be greatly appreciated. Thanks
I checked your code and it's kinda worked for me, but I will still modify it like this:
(EventStartDateTime >= GetDATE()) OR (EventStartDateTime IS NULL)
Because second part where you compare 'Date and time' field with empty string is not correct. So in your case, you don't get any data if 'EventStartDateTime' is not populated for every item. If that is not the case, you should try remove WHERE condition and check if you get data without it.
Best regards,
Dragoljub
Your statement will work with a macro like so:
(EventStartDateTime >= '{% CurrentDateTime.ToShortDateString() %}')
Your second condition would not work because your EventStartDateTime field is (assumed) to be a DateTime object so checking for an empty string will not work. You need to check for NULL.

Zoho Creator making a custom function for a report

Trying to wrap my head around zoho creator, its not as simple as they make it out to be for building apps… I have an inventory database, and i have four fields that I call to fill a field called Inventory Number (Inv_Num1) –
First Name (First_Name)
Last Name (Last_Name)
Year (Year)
Number (Number)
I have a Custom Function script that I call through a Custom Action in the form report. What I am trying to do is upload a CSV file with 900 entries. Of course, not all of those have those values (first/last/number) so I need to bulk edit all of them. However when I do the bulk edit, the Inv_Num1 field is not updated with the new values. I use the custom action to populate the Inv_Num1 field with the values of the other 4 fields.
Heres is my script:
void onetime.UpdateInv()
{
for each Inventory_Record in Management
{
FN = Inventory_Record.First_Name.subString(0,1);
LN = Inventory_Record.Last_Name.subString(0,1);
YR = Inventory_Record.Year.subString(2,4);
NO = Inventory_Record.Number;
outputstr = FN + LN + YR + NO;
Inventory_Record.Inv_Num1 = outputstr;
}
}
I get this error back when I try to run this function
Error.
Error in executing UpdateInv workflow.
Error in executing For Each Record task.
Error in executing Set Variable task. Unable to update template variable FN.
Error evaluating STRING expression :
Even though there is a First Name for example, it still thinks there is none. This only happens on the fields I changed with Bulk Edit. If I do each one by hand, then the custom action works—but of course then the Inv_Num1 is already updated through my edit on success functions and makes the whole thing moot.
this may be one year late, you might have found the solution but just to highlight, the error u were facing was just due to the null value in first name.
you just have put a null check on each field and u r good to go.
you can generate the inv_number on the time of bulk uploading also by adding null check in the same code on and placing the code on Add> On Submt.( just the part inside the loop )
the Better option would be using a formula field, you just have to put this formula in that formula field and you'll get your inventory_number autogenerated , you can rename the formula_field to Inv Number or whaterver u want.
Since you are using substring directly in year Field, I am assuming the
year field as string.else you would have to user Year.tostring().substring(2,4) & instead of if(Year=="","",...) you have to put if(Year==null , null,...);
so here's the formula
if(First_Name=="","",First_Name.subString(0,1))+if(Last_Name =="","",Last_Name.subString(0,1)) + if(Year=="","",Year.subString(2,4)+Number
Let me know ur response if u implement this.
Without knowing the datatype its difficult to fix, but making the assumption that your Inventory_Record.number is a numeric data item you are adding a string to a number:
The "+" is used for string Concatenation - Joiner but it also adds two numbers together so think "a" + "b" = "ab" for strings but for numbers 1 + 2 = 3.
All good, but when you do "a" + 2 the system doesn't know whether to add or concatenate so gives an error.

Adding an error message to return. SQL Server

Well, I'm trying to construct some error reporting.
Current snippet of code, which will put into a stored procedure after I get this code correct...
begin
select *
from dbo.DIM_S17_Detail
Where ((LEN(New_Acc_Flag) >1 or ISNUMERIC (Substring(New_Acc_flag, 1, 1)) = 1))
end
So, the defined datatype is either a Y/N - Alphanumeric, so it picks out ISNUMERIC as 1, so it will bring up the selected records which ARE numeric - so these records are incorrect...
I hope you still follow...
So, if a 'New_Acc_Flag' is TRUE, it will bring up those record(s) and should return a message something like "Y/N not selected" or "Y/N Value only".
Thanks again.
Please bear in mind I'm a noobie to SQL.
If I understand what you want correctly you can use THROW or RAISERROR

Visual Basic- "IF" doesn't end

If My.Computer.FileSystem.FileExists("pack/locale_ro.epk") Then My.Computer.FileSystem.DeleteFile("pack/locale_ro.epk")
PB_GSM.Value = 10
If My.Computer.FileSystem.FileExists("pack/locale_ro.eix") Then My.Computer.FileSystem.DeleteFile("pack/locale_ro.eix")
PB_GSM.Value = 20
If My.Computer.FileSystem.FileExists("pack/root.epk") Then My.Computer.FileSystem.DeleteFile("pack/root.epk")
PB_GSM.Value = 30
If My.Computer.FileSystem.FileExists("pack/root.eix") Then My.Computer.FileSystem.DeleteFile("pack/root.eix")
PB_GSM.Value = 40
My.Computer.Network.DownloadFile("http://example")
I believe i wrote everything correct, but it doesn't matter how i write the "if"-s , i can not end them. if i wrote End if next to a line it says something like "End if must be preceded by a matching if".
And another problem , the line about the download link is underlined and it says"Overload resolution failed because no accessible 'DownloadFile' accepts this number of arguments".
P.S: this is a try for a metin2 patcher, i do not know exactly how to do it but i'm sure this is a way to update the game only at the files that i neeed.Thanks for help:)
You have them all in one line. Don't put anything after the "Then" keyword.
If My.Computer.FileSystem.FileExists("pack/locale_ro.epk") Then
My.Computer.FileSystem.DeleteFile("pack/locale_ro.epk")
PB_GSM.Value = 10
End If
If looking for an else-if situation, this would be the syntax:
If My.Computer.FileSystem.FileExists("pack/locale_ro.epk") Then
My.Computer.FileSystem.DeleteFile("pack/locale_ro.epk")
PB_GSM.Value = 10
ElseIf My.Computer.FileSystem.FileExists("pack/locale_ro.eix") Then
My.Computer.FileSystem.DeleteFile("pack/locale_ro.eix")
PB_GSM.Value = 20
' etc, etc
End If
Note though that this will only run the code on the first "True" line found.
For the DownloadFile, you also need to specify the destination:
My.Computer.Network.DownloadFile("http://example", "c:\temp\myfile.txt")
Substitute the c:\temp\ path with the one you are using.
When you post the Then statement followed by an expression that closes that If statement. You have, in essence, already closed all your If statements.