Getting Invalid Column name Error in T-SQL while performing Update operation - sql

I am trying to run a SQL query which is quite straightforward. The query is:
UPDATE dbo.Machine
SET dbo.Machine.ServerName="Server"
WHERE dbo.Machine.ServerName IS NULL;
I am getting the following error on Server
Invalid column name 'Server'.
Am I missing something ?

String should be declared with single quotes ' '
SET dbo.Machine.ServerName= 'Server'
Double quotes is for fieldnames

Related

Cannot query my container using the GridDB Shell?

I have a device container with the name 1cbfce15ec4d which houses some my data. I know for a fact there's data in there, but when I try a simple query in the griddb shell, I got the following error:
gs[public]> sql select * from 1cbfce15ec4d;
D20332: An unexpected error occurred while executing a SQL. : msg=[[240001:SQL_COMPILE_SYNTAX_ERROR] Parse SQL failed, reason = Syntax error: 1cbfce15ec4d; on executing query (sql="select * from 1cbfce15ec4d") (db='public') (user='admin') (appName='gs_sh') (clientId='a6d92f48-e558-440-86dd-a05e949fa726:1') (clientNd='{clientId=3, address=127.0.0.1:55744}') (address=127.0.0.1:20001, partitionId=983)]
I am not exactly sure what is going on here -- at first I assumed my data must be corrupt or empty, but that is not the case. It seems to be a case of the shell dying trying to process something about that container name.
Any ideas?
According to the manual :
"If the name of a table or a column contains characters other than ASCII alphanumeric characters and underscore, or if the first character of the name is a number in a SQL statement, enclose the name with double quotation marks."
Try select * from "1cbfce15ec4d"

Syntax error in my SQL when inserting a JSON field

Why this query is not working:
UPDATE country SET timezones="[{"zoneName":'Asia\/Kabul',"gmtOffset":16200,"gmtOffsetName":'UTC+04:30',"abbreviation":'AFT',"tzName":'Afghanistan Time'}] " where name='Afghanistan'
Error I get:
ERROR: syntax error at or near "zoneName"
LINE 1: UPDATE country SET timezones="[{"zoneName":'Asia/Kabul',"gm...
^
SQL state: 42601
Character: 34
the issue with your SQL statement is that the literal string you are trying to set timezones to contains improperly formatted escape characters. if you wanted to avoid that first error you can double up on quotes like timezones="[{""zoneName"": ...
you can go to the link to see more about string formating in SQL. good luck!
You're trying to update the value wrapping the string in quotes. You need to wrap the string in single quotes timezones='[{"zoneName":'Asia...}]'
However, to TitledTeapot's point, you will also have to escape the existing single quotes in your string, so you'd end up with something like this:
'[{"zoneName":''Asia\/Kabul'',"gmtOffset":16200,"gmtOffsetName":''UTC+04:30'',"abbreviation":''AFT'',"tzName":''Afghanistan Time''}]'

Postgres syntax error when using 'like' in single quote

I am getting a syntax error in a PostgreSQL query. I am working on a project developed in YII1, I am getting an error
CDbCommand failed to execute the SQL statement: SQLSTATE[42601]:
Syntax error: 7 ERROR: syntax error at or near "s" LINE 1: ...OT NULL
AND sub_heading like '%Women and Children's Voices%'.
As you can see above, I am using the like operator in single quotes, and in the string there is another single quote (Children's). So PostgreSQL is throwing me an error. Please provide me a solution to escape the string.
You can escape a single quote in a string by using another single quote (i.e., '' instead of '. Note that these are two ' characters, not a single " character):
sub_heading LIKE '%Women and Children''s Voices%'
-- Here -----------------------------^
You should use the format function to construct the SQL statement, using the %L placeholder for the pattern.
I solved this problem by replacing the single quote with double quotes using PHP. Here is the code
There is a variable $var with value Women and Children's Voices. I replace that single quote using the str_replace() function.
$var = str_replace("'", "''", $var);

Hive -character '<EOF>' not supported here

Select * from mytable where field=
'ce7bd3d4-dbdd-407e-a3c3-ce093a65abc9;cdb597073;7cf6cda5fc'
Getting Below Error while running above query in Hive
FAILED: ParseException line 1:92 character '' not supported here
<EOF> here means End Of File. When you get an "unexpected End Of File" error it means the parser reached the end of the query unexpectedly. This typically happens when the parser is expecting to find a closing character, such as when you have started a string with ' or " but have not closed the string (with the closing ' or ").
When you come across these types of errors it is good to check that your query can be parsed correctly. In addition, the error gives you the location where the parser failed: line 1:92 in this case. You can usually look at this location (character 92 of the query) and work backwards to find the problem character.
Try adding the database name to the "from" statement as below.
Select * from my_db_name.mytable where field= 'ce7bd3d4-dbdd-407e-a3c3-
ce093a65abc9;cdb597073;7cf6cda5fc';
Hive uses the default database when no database was previously specified.

ORA-01722: invalid number

When i execute the below SQL command using single quotes to enter a number, i got an error
if remove the single quotes,it is successfully updated. knowing that the type of the field HEIGHT is NUMBER.
The strange thing is that i tried to use the same sql statement with single quotes on different machines, some machines execute it successfully, others do not.(same oracle version,same table structure...)
Any explanation please
SQL> UPDATE TBL_DEVICE_INFO SET HEIGHT='14.5' WHERE ID='6ujbfI';
UPDATE TBL_DEVICE_INFO SET HEIGHT='14.5' WHERE ID='6ujbfI'
*
ERREUR à la ligne 1 :
ORA-01722: invalid number
SQL> UPDATE TBL_DEVICE_INFO SET HEIGHT=14.5 WHERE ID='6ujbfI';
1 row updated.
This is most likely a locale problem.
That is, some machines have the decimal symbol "." (period), and some have "," (comma).
You can test it by putting it like this:
UPDATE TBL_DEVICE_INFO
SET HEIGHT = to_number('14.5', '99D9','NLS_NUMERIC_CHARACTERS = ''. ''')
WHERE ID='6ujbfI'
When the number is in single qoutes, oracle will do an implicit conversion to number using the characters set in the database.
You can change the default by setting the NLS_NUMERIC_CHARACTERS parameter:
alter session set NLS_NUMERIC_CHARACTERS = '. ';
but that will also reflect to data returned by the system so make sure that it doesn't break anything in your application if you change that.
Strings should be quoted using single quotes, numbers shouldn't be.
Maybe you're using a different client on the machines where the invalid syntax works?