I’m new to SQL, but can handle some very basic clauses. Can anyone tell me what’s wrong with the following statement?
SELECT top 10 *
FROM inventory
WHERE UPC=‘104270’;
The error message is:
Incorrect syntax near ‘’’.
I’ve confirmed that all spelling is correct, including tablename (inventory) and condition (UPC).
You're using the ’ character instead of a single-quote '.
Replace your ’s with 's and you should be fine.
Solutions : ’ Replace with single-quote '
SELECT top 10 * FROM inventory WHERE 'UPC'='104270';
Helpful :)
Related
I have values in the SQL statement as follows, for example
'$.Company_ID'
Important are the symbol: **'**. I also need to have this as string.
So I try to get it like this:
SELECT
CONCAT('**'$.**',+ AttsData.[key], '**'**') AS XYZ
FROM
Testtable
So as result I want to get a column which has values like
**'$.Company_ID'**
But it is not possible to concat the symbol **'** like '**'**'.
Do you have an idea how I can solve this problem.
Thank you in Advance.
I think you just need to escape the quotes (which you commonly do by doubling up) - also not sure why you have + as part of your concat, try:
CONCAT('**''$.**', AttsData.[key], '**''**')
I am trying to concat two columns with concat and concat_ws function. Along with concatinating two columns I also want to append a word to this concatination. So I tried to achieve that using below method
SELECT CONCAT(CONCAT("SRID=4326;POINT(", CONCAT_WS(" ",cast(A.longitude as string),cast(A.latitude as string))), ")") as the_geom
FROM test
With above syntax I am getting the following error.
**org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 1:13 cannot recognize input near 'CONCAT' '(' 'CONCAT' in expression specification**
I was not knowing what wrong I am doing in the above syntax. Is there any alternative way to achieve this.
Expected RESULT : SRID=4326;POINT(127.155104 35.8091378)
I tried all ways using concat and concat_ws, but getting syntax issues.
The problem is semicolon, it breaks the query. Try replacing semicolon with \073, also double backslash may work \\;
Also it seems single concat is enough.
Demo using \073 :
with test as (
select 12134.12345 as longitude, 12134.12345 as latitude
)
SELECT CONCAT("SRID=4326\073POINT(",
CONCAT_WS(" ",cast(A.longitude as string),cast(A.latitude as string))
, ")"
) as the_geom
FROM test A
Result:
SRID=4326;POINT(12134.12345 12134.12345)
I am struggling with this issue. I am trying to enclose my data in \001 and remove the odd character out for etl purpose in sql server. But if you see the last line, there seems to be a carriage return character, but does not work when i try to remove it. I have tried replace(replace(column,char(10),''),char(13),'')). The below is when I do a less of the column, but do not know what the character is. has anyone experienced this issue before?
Any suggestions welcome.
^A011111^A
^A012345^A
^A001231231^A
^A000213123123112^A
^A
^A
please let me know if you have any questions.
Use the below script.
SELECT REPLACE(column,CHAR(13)+CHAR(10),'')
see one sample scenario.
DECLARE #input VARCHAR(50)=CHAR(13)+CHAR(10)+'Hello'+CHAR(13)+CHAR(10)+'world'+CHAR(13)+CHAR(10)
SELECT LEN(#input) --OUTPUT : 16
Removing all the carriage symbol
SELECT LEN(REPLACE(#input,CHAR(13)+CHAR(10),'')) --OUTPUT : 10
If you want remove carriage symbol from right end of a string,use the below query
SELECT #input=LEFT(#input,LEN(#input)-PATINDEX('%[^'+CHAR(13)+CHAR(10)+']%',REVERSE(#input))+1)
SELECT LEN(#input) --OUTPUT : 14
If you wanted to remove carriage symbol from right end of a string,use the below query
SELECT #input=RIGHT(#input,LEN(#input)-PATINDEX('%[^'+CHAR(13)+CHAR(10)+']%',#input)+1)
SELECT LEN(#input) --OUTPUT : 12
try this
select replace(replace(#input,'^A',''),char(13),'')
This is really starting to hurt!
I'm attempting to write a query in Oracle developer using a regex condition
My objective is to find all last names that contain charachters not commonly contained in names (non-alpha, spaces, hyphens and single quotes)
i.e.
I need to find
J00ls
McDonald "Macca"
Smithy (Smith)
and NOT find
Smith
Mckenzie-Smith
El Hassan
O'Dowd
My present query is
select * from dm_name
WHERE regexp_like(last_name, '([^A-Za-z -])')
and batch_id = 'ATEST';
which excludes everything expected except the single quote. When it comes to putting the single quote character, the Oracvel SQL Develoepr parser takes it as a literal.
I've tried:
\' -- but got a "missing right parenthesis" error
||chr(39)|| -- but the search returned nothing
'' -- negated the previous character in the matching group e.g. '([^A-Za-z -''])' made names with '-' return.
I'd appreciate anything you could offer.
Just double the single quote to escape your quote.
So
select *
from dm_name
where regexp_like(last_name, '[^A-Za-z ''-]')
and batch_id = 'ATEST'
See also this sqlfiddle. Note, I tried a similar query in SQL developer and that worked as well as the fiddle.
Note also, for this to work the - character has to be the last character in the group as otherwise it tries to find the group SPACE to ' rather than the character -.
The following works:
select *
from dm_name
WHERE regexp_like(last_name, '([^A-Za-z ''-])');
See this SQLFiddle.
Whether SQL Developer will like it or not is something I cannot attest to as I don't have that product installed.
Share and enjoy.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
SQL Server LIKE containing bracket characters
I am having a problem with pattern matching.I have created two objects say,with codes
1)[blah1]
2)[blah2] respectively
in the search tab,suppose if i give "[blah" as the pattern,its returning all the strings
i.e., [blah1] and [blah2]
The query is
select *
from table1
where code like N'%[blah%'
I guess the problem is with the condition and special characters. Please do revert if you have as solution. Is there any solution where we can escape the character"[". I tried to change the condition as N'%[[blah%'.But even then its returning all the objects that is in the table.
When you don't close the square bracket, the result is not specified.
However, the story is different when you close the bracket, i.e.
select *
from table1
where code like N'%[blah%]%'
In this case, it becomes a match for (any) + any of ('b','l','a','h','%') + (any). For SQL Server, you can escape characters using the ESCAPE clause.
select * from table1 where code like N'%\[blah%\]%' escape '\'
SQL Fiddle with examples
You can escape a literal bracket character this way:
select *
from table1
where code like N'%[[]blah%'
Source: LIKE (Transact-SQL), under the section "Using Wildcard Characters As Literals."
I guess this is Microsoft's way of being consistent, since they use brackets to delimit table and column identifiers too. But the use of brackets is not standard SQL. For that matter, bracket as a metacharacter in LIKE patterns is not standard SQL either, so it's not necessary to escape it at all in other brands of database.
As per My understanding, the symbol '[', there is no effect in query. like if you query with symbol and without symbol it shows same result.
Either you can skip the unwanted character at UI Level.
select * from table1 where code like '%[blah%'
select * from table1 where code like '%blah%'
Both shows same result.