syntax error in access when using iif in query expression - ms-access

I'm trying to create a Query based on an evaluation of an empty field.
Item: [Huis] & IIf(IsNull([Naam]), "", " / " & [Naam]) & IIf(IsNull([Druif]), "", " / " & [Druif]) & iif(IsNull([Type]), "", " / " & [Type])
It gives me a syntax error: Missing an operand or operator, you have entered an invalid character or comma or you have not enclosed the text in the expression in quotation marks.
I have tried other examples that are supposed to work here on stackoverflow, they all give the same error. What am I doing wrong?

I don't see an error either, but you can simplify your expression by taking advantage of the fact that & concatenates NULL values, but + doesn't.
Item: [Huis] & (" / " + [Naam]) & (" / " + [Druif]) & (" / " + [Type])
Each block, e.g. (" / " + [Naam]) will be NULL if the field is NULL.

Related

SSRS expression not displaying the right values

I'm trying to run the following expression:
=IIF((Fields!EntryFirstName.Value = " ") And (Fields!EntryLastName.Value = " " ),
"Team:" & Fields!TeamName.Value, Fields!EntryOrder.Value & " . "
& Fields!EntryFirstName.Value & " " & Fields!EntryLastName.Value)
The table that the following is looking at is this one :
However running the above expression will only return the following ( where EntryFirst name is the column EntryfirstName and so on):
Fields!EntryOrder.Value & " . "
& Fields!EntryFirstName.Value & " " & Fields!EntryLastName.Value
for the whole report ( this one expression is part of a row group, if that would change anything)

you have an error in your sql syntax

Here is my query
result = s.executeUpdate("INSERT INTO order " + "VALUES ('" + id.getText() + "','" + name.getText() + "', '" + code.getText() + "','" + price.getText() + "')");
I am getting this exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'order VALUES
(('1'),('1'),( '1'),('1')' at line 1
Order is a reserved word -- I wouldn't use it as a table name, but if you are stuck with it, just put back ticks around it. INSERT INTO `order` ...
You need to use backticks for reserved keywords,
result = s.executeUpdate("INSERT INTO `order` " + "VALUES ('" + id.getText() + "','" + name.getText() + "', '" + code.getText() + "','" + price.getText() + "')");
Also your code is prone to SQL injection. So you need to work on that as well. My suggestion is to use prepared statement to avoid SQL injection.
Also a good read: Preventing SQL Injection in Java
Ensure that none of your getters are sending characters that may cause the query be syntactically incorrect.
If your getter is returning a reserved character like the following:
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "#"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
*Then the statement will not function as intended.
This is why sanitation of inputs is important for any statement.
See more on allowed unencoded in query strings:
http://www.456bereastreet.com/archive/201008/what_characters_are_allowed_unencoded_in_query_strings/

syntax error at insert into

i need to insert some informations from a form to a table fields, i tried this code:
Dim sql As String
sql = " insert into récapRELAIS( Région, Groupe, Agence, N°personne,
Nom du client, N°prêt, Durée, Nature du prêt, Encours client)
Values ("
& Me.Region & " , " & Me.Groupe & " , "
& Me.Agence & " , " & Me.Num_Personne & " , "
& Me.Nom_client & " , " & Me.Num_Contrat & " , "
& Me.Montant_prêt & ", " & Me.Durée_prêt & " ,"
& Me.Nature_prêt & " , " & Me.Encours & "); "
DoCmd.RunSQL sql
but it doesn't work, it says that i have an error type 3134
The problem are most likely your field names with spaces.
Solution: Surround with square brackets - [ ], like this:
insert into récapRELAIS( Région, Groupe, Agence, [N°personne],
[Nom du client], [N°prêt], Durée, [Nature du prêt], [Encours client])
I am also not sure if the ° sign is working.
In general, I advice you to not take spaces or special characters or diacritics like ê è é for database field names.
Formatting and pretty display should take place in the user interface; but the database is more a programming environment, and there, it's better to just use the basic characters A-Z and 0-9.

SSRS datepart expression, Error

I didnt know whats wrong with this expression.This expression always return #error.how to solve this?
=MonthName(datepart("M",format(Fields!date.Value,"yyyy-MM-dd"))) + " " + datepart("yyyy",format(Fields!date.Value,"yyyy-MM-dd"))
expression works fine with just=MonthName(datepart("M",format(Fields!date.Value,"yyyy-MM-dd"))), when added + " " + datepart("yyyy",format(Fields!date.Value,"yyyy-MM-dd")) become error.curious.
Use & instead of + to concatenate strings in SSRS expressions - Operators in Expressions (Report Builder and SSRS)
=MonthName(datepart("M",format(Fields!date.Value,"yyyy-MM-dd"))) & " " & datepart("yyyy",format(Fields!date.Value,"yyyy-MM-dd"))
Try ===>
=MonthName(datepart("m",format(Fields!date.Value,"yyyy-MM-dd"))) + " " + datepart("y",format(Fields!date.Value,"yyyy-MM-dd"))

Trying to replace a certain character in SSRS

I am trying to replace a the charater 0 when pulling through a report. I have entered the expression below and when I run my report I get a #Error any hints on what I am doing wrong?
Thanks
=IIf(Fields!HomeAddress2.Value & " " & Fields!HomeAddress3.Value & " " &Fields!HomeAddress4.Value = 0, Fields!HomeAddress2.Value & " " & Fields!HomeAddress3.Value & " " &Fields!HomeAddress4.Value, "")
Isn't it similar to NULL?
Maybe you can try ISNULL( <your expression>, " ")