I am using SQL Server 2008 R2. I want the retrieve the row from table in which data is other than than English.
But when I type the command it returns me nothing.
SELECT *
FROM PARTY
WHERE NAME LIKE 'رانا عطا ربانی'
ORDER BY SRNO
Any suggestions, how to retrieve record like that?
Have you tried declaring the string literal as unicode?
SELECT * FROM PARTY
WHERE NAME LIKE N'رانا عطا ربانی'
ORDER BY SRNO
[This will show you all string-related columns in your database, and their collation: Collation conflict SQL Server 2008 ]
Related
I linked an Oracle Database to my SQL Server in Microsoft SQL Server Management Studio 18. Server Objects -> Linked Servers.
I have a SQL Statement that when I run on the Oracle Developer Tool/Platform it returns the information as expected. But when I run the exact same query on the SQL Server it returns the incorrect results (The actual values in the rows and columns do not match).
What I know.
The table I am query in lives in the Oracle Database.
I can get the same/matching results on the Oracle Developer and SQL Server if I exclude in my WHERE statement anything involving a DATE.
Any thoughts?
The example of the query below.
Works on Oracle Developer but not on MSSQL
SELECT * FROM TABLE1
WHERE status = 'Deviation' and trunc(SRC_ROW_UPDT) BETWEEN TO_DATE('01/03/2020', 'DD/MM/YYYY') AND TO_DATE('10/12/2020','DD/MM/YYYY');
The example of the query below.
Works on both Oracle Developer and MSSQL
SELECT * FROM TABLE1
WHERE status = 'Deviation' and BATCHID = 'ThisBAtchID';
You cannot use ORACLE specific functions like TO_DATE in SQL Server calls. You have to execute them remotely using OPENQUERY. OPENQUERY in MSDN
SELECT * FROM OPENQUERY (OracleSvr, 'SELECT * FROM TABLE1
WHERE status = ''Deviation'' and trunc(SRC_ROW_UPDT) BETWEEN TO_DATE(''01/03/2020'', ''DD/MM/YYYY'') AND TO_DATE(''10/12/2020'',''DD/MM/YYYY'');');
In Oracle for e.g.
create table test1(Prod_Name varchar2(30))
insert into test1 values('CHANNEL')
insert into test1 values('SHELL')
insert into test1 values('_DISTRIBUTOR BELT')
select * from test1 order by prod_name asc
Select query gives the following result
Prod_Name
CHANNEL
SHELL
_DISTRIBUTOR BELT
but in SQL Server it giving following result
Prod_Name
_DISTRIBUTOR BELT
CHANNEL
SHELL
I want the result to be the same as Oracle in SQL Server so how to write query. To clarify, I want CHANNEL, SHELL, and _DISTRIBUTOR BELT row in last
In SQL Server you can force the collation when using COLLATE. Try this below script and you should get your expected output this way.
DEMO HERE
SELECT *
FROM test1
ORDER BY prod_name
COLLATE SQL_Latin1_General_CP850_BIN2
This is tricky. Oracle and SQL Server have different sorting rules. Oracle by default does binary sort, which is based on the numeric values of the characters defined by the character encoding scheme (this is the fastest method).
The underscore character (_) has ASCII code 95, while A-Z range from 65 to 90. Hence the results that you are seeing.
One way to produce the expected results is to do a linguistic sort: with this setting, characters are sorted independently of their numeric values in the character encoding scheme.
I played around with the parameters, and here is a solution that sorts as expected:
select * from test1 order by nlssort(prod_name, 'nls_sort = punctuation')
Demo on DB Fiddle
Please note that this will be slower than doing a binary sort.
I have to convert a DB2 query to SQL Server, but don't understand what exactly below query does:
SELECT
t.MyColumnA NAME(MyColumnA-01),
t.MyColumnA COLHDG("COA" "VALUE")
FROM
MyTable t
It looks like the NAME and COLHDG functions are just UI functions specific to HelpSystems. The actual query would be
SELECT t.MyColumnA AS "COA VALUE"
FROM MyTable t
I have an Oracle database containing my data and an SQL Server database getting the data from Oracle through DBLink.
Problem is - all numbers from the Oracle tables are accepted at the SQL Server as nvarchar. As a result, when i try to filter the query in the SQL Server with some_number_field = 0 i get:
"Conversion failed when converting the nvarchar value '3.141' to data type int."
This also happens if i try to select "some_number_field * 1" or similar expressions.
Any idea ?
Today I ran into the same kind of problem. It seems that Oracle field with datatype NUMBER are shown as nvarchar where querying through a linked server. However, NUMBER(x,y) not.
E.g. colB is the NUMBER field from an Oracle View (or table)
Try this:
SELECT colA, CAST(colB AS DECIMAL(23,2)) colB
FROM OPENQUERY(LINKED_SERVER_NAME, 'select * from myView')
Note: the DECIMAL(xx,y) values depends of course on your data. Also, remember, if your NUMBER column is a repetitive fraction (eg. 33.33333333 etc), you need to place a round() on the oracle side otherwise the CAST will throw an error.
i am working with sql and got stuck in issue,
i am using sql server 2012 r2.
i have a table (info) with 2 columns id (int) and names varchar(max).
in the names column i have stored coma(,) separated list of names, like marry,rita,johan,david,.
now i want to get the id where names is david.
select id from info where names='david'
how it is possible in sql, i know we can do it in c# by using string.substing but is it possible in sql?
Try this:
SELECT id FROM info
WHERE names LIKE '%david%'
It will return the id of the record if the column names contains 'david'.
Read more about LIKE operator here.