I am working on 2 versions of SQL Server i.e 2005 and 2008 R2.
From 2008 R2 I have created a linked server which will connect to an older SQL Server 2005 instance.
I have one table on my server (2008) which is as below
members
id name
0002320 AOne Enterprises Motihari
0002321 AOne Enterprises Siliguri
Another table which resides on remote server contain activity of each agent
id member_code agent rr_no txn_date amount
I fired a query below
select top 5 *
from [192.168.6.3].sync.dbo.agents_log
where member_code IN
(select id from members where name like 'AOne Enterprises%')
I was trying to pull all activity log of AOne Enterprises through out the country which is in distributed database , so I need to create a link servers.
I got this error:
Msg 468, Level 16, State 9, Line 1
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_BIN" in the equal to operation.
not exactly sure what you need, but if its only collation issue you can do below
SELECT TOP 5 *
FROM [192.168.6.3].sync.dbo.agents_log
WHERE member_code COLLATE SQL_Latin1_General_CP1_CI_AS
IN (SELECT id
FROM members
WHERE NAME LIKE 'AOne Enterprises%')
I just added COLLATE SQL_Latin1_General_CP1_CI_AS , perhaps it work
Related
I have a database in Azure SQL Server with collation as 'SQL_Latin1_General_CP1_CS_AS' and in that i have table that has two columns
CREATE TABLE DBO.TABLE1(
[ROWID] [numeric](16, 0) IDENTITY(1,1) NOT NULL,
[CODE] [varchar](10) NOT NULL,
)
Now below query works fine in Azure SQL ignoring the case sensitivity of column names
SELECT rowID, coDE FROM DBO.TABLE1
SELECT rowid, code FROM DBO.TABLE1
But when i create the database on a Sql Server inside Azure VM (IaaS solution) with same collation setting: 'SQL_Latin1_General_CP1_CS_AS' then above queries are not working at all its throwing below error:
Msg 207, Level 16, State 1, Line 1
Invalid column name 'rowid'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'code'.
How do i suppress this case sensitivity of column name while querying tables in Sql server on Azure VM.
Please advice.
Azure SQL Database always uses contained database collation, which allows you to have a case-sensitive database without having a case-sensitive catalog (yuck).
In a contained database, the catalog collation
Latin1_General_100_CI_AS_WS_KS_SC. This collation is the same for all
contained databases on all instances of SQL Server and cannot be
changed.
In SQL Sever on an Azure VM you can get the same behavior by using a contained database. Your database collation (and the default collation of all your table columns) can be SQL_Latin1_General_CP1_CS_AS, but your table names, column names, proc names, etc will use the case-insensitive Latin1_General_100_CI_AS_WS_KS_SC.
SQL_Latin1_General_CP1_CS_AS is case-sensitive, compare to SQL_Latin1_General_CP1_CI_AS which is case-insensitive. It's better to change your DB collation.
I read in SQL Server documentation that I can specify column names in FROM clause of a simple SELECT query.
But when I try to run this query:
select * from my_db.dbo.test_table.test;
I get the following error:
Msg 7202, Level 11, State 2, Line 1 Could not find server 'my_db' in
sys.servers. Verify that the correct server name was specified. If
necessary, execute the stored procedure sp_addlinkedserver to add the
server to sys.servers.
I know this is a T-SQL page, and I'm trying to run .
Why does this happen?
I'm using SQL Server version 2017 via Microsoft SQL Server Management Studio version 2017 as well.
try rewriting from this
select * from my_db.dbo.test_table.test;
to this
select test_table.test,* from my_db.dbo.test_table;
the way it was written with that many Periods it assume you are trying to fully qualify the table so in what you had tried to the server is treating it as follows
my db = linked server (a server other than the Server you are working on)
dbo = Schema (which is correct)
test_table = Table (Also correct)
test = just plain erroror
the fields you want to show should directly follow the Keyword Select so if you only wanted 2 fields you could write
select test,test2 from my_db.dbo.test_table;
or simpler if you only have the one server
select test,test2 from dbo.test_table;
or if you only have the defailt Schema dbo (Database Base Owner)
select test,test2 from test_table;
I hope thaelps
You cannot specify columns in the FROM clause, but you can specify columns in the SELECT clause.
select test from my_db.dbo.test_table
Please run sp_addlinkedserver and sp_addlinkedsrvlogin SPs:
EXEC sp_addlinkedserver #server='MyLinkedServer'
EXEC sp_addlinkedsrvlogin 'MyLinkedServer', 'false', NULL, 'MyUserName', 'MyPassword'
After that, you can try to run: select * from my_db.dbo.test_table
Ref: https://blog.sqlauthority.com/2014/08/26/sql-server-fix-error-7202-could-not-find-server-in-sys-servers-verify-that-the-correct-server-name-was-specified/
Also, even though it is SQL Server 2014 related maybe helps, please see: Could not find server 'server name' in sys.servers. SQL Server 2014
In SSMS 2012, I have created a linked server in SERVERA to SERVERB from which I have successfully written queries to multiple tables within the DBB database using a four part reference.
When I try to reference the 'Charge' table in the 'DBB' database with a simple select statement:
SELECT * FROM [SERVERB].[DBB].dbo.Charge
I get the following message:
Msg 207, Level 16, State 1, Line 1 Invalid column name 'charge_type'.
This column exists in the DBB database as 'Charge_Type', however, the collation of SERVERB is case insensitive, whereas the collation of SERVERA is case sensitive (which is where, I believe, my problem lies).
Does anyone have experience with this issue?
(For the people who might end up here)
You can change the collation on the fly. In this case, you have to write the name of the column names in the select query. What I mean is,
rather than writing query like this:
SELECT * FROM [SERVERB].[DBB].dbo.Charge
write the query like this:
SELECT Charge_Col1, Charge_Col2, Charge_Type COLLATE Latin1_General_CI_AS FROM [SERVERB].[DBB].dbo.Charge
There is another post similar to this: how we can select two columns having different collation
SELECT * from TABLE_attendance
WHERE date NOT IN
(SELECT * from [LINKED SERVER].DATABASENAME.dbo.TABLE_attendance where date = '06-09-15')
When I executed this query I got this error message:
Msg 116, Level 16,
State 1, Line 3 Only one expression can be specified in the select
list when the subquery is not introduced with EXISTS.
I just wanted to check a records in linked server if the records are all existing from local server , if the linked server has no record on an specific date, then the local server will transfer data into linked server.
Please help me to solve this problem, Thank you :-)
You cannot return more than one column in your subquery. Your query should be something like this
SELECT * from TABLE_attendance
WHERE id NOT IN (SELECT id
from [LINKED SERVER].DATABASENAME.dbo.TABLE_attendance
where date = '06-09-15')
I have numerous databases in compatibility_level of 80 (SQL Server 2000);
I need to execute the following:
select
sf.fileid, sf.groupid, sf.name, sf.filename, mf.database_id
from
sys.sysfiles sf
JOIN
sys.master_files mf ON sf.filename = mf.physical_name COLLATE DATABASE_DEFAULT
CROSS APPLY
sys.dm_os_volume_stats (mf.database_id, sf.fileid)
But I get the following error:
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '.'.
I cannot change the compatibility mode and I have no idea how I can run this specific script for my database from the context of master db.
In SQL Server 2000 there were no 'sys' files. Many had equivalents and you can see a good chart at:
http://www.mssqltips.com/sqlservertip/1037/system-information-in-sql-server-2000-vs-sql-server-2005/
In 2000 for example there was a dbo.sysfiles but no sys.sysfiles. These tables do not necessarily contain the same columns.....
"CROSS APPLY" is not allowed in earlier versions of the SQL as well in databases running in older compatibility models.