I'm facing a difficult to run 'SUM' syntax from a linked server(PostgreSQL) in MSSQL, the connection created via ODBC driver.
If I only retrieve the data, there isn't any problem,
select * from OpenQuery([192.168.1.145],'
select party_code, amount_forex from biv_so_main
')
If I try to sum the value, it throws an error,
select * from OpenQuery([192.168.1.145],'
select party_code, sum(amount_forex) from biv_so_main group by party_code
')
Error message
The OLE DB provider "MSDASQL" for linked server "192.168.1.145" supplied inconsistent metadata for a column. The column "sum" (compile-time ordinal 2) of object "
select party_code, sum(amount_forex) from biv_so_main group by party_code
" was reported to have a "SCALE" of 6 at compile time and 2 at run time.
I googled a lot, seems nobody has the same issue like me, anybody can help?
Thanks.
add an alias to your sum column and cast into a datatype (into whatever type amount_forex is).
select * from OpenQuery([192.168.1.145],'
select party_code
, sum(amount_forex)::int amount_forex_sum
from biv_so_main group by party_code
')
Related
I'm new to Microsoft SQL Server 2014. I run this SQL code:
SELECT TOP(10) 'DBSG' as seek_entity, *
FROM DBSG..PM00200
and get this result:
Next, I want to find out total line items for that entity with code below.
WITH vw_pm00200_all AS
(
SELECT TOP(10)
'DBSG' as seek_entity, *
FROM
DBSG..PM00200
)
SELECT
seek_entity,
COUNT(*) AS total
FROM
vw_pm00200_all
GROUP BY
1
Sadly, I get this error. I have no idea why it failed.
Msg 164, Level 15, State 1, Line 9
Each GROUP BY expression must contain at least one column that is not an outer reference.
Lastly, please advise is Microsoft SQL Server based on Transact-SQL?
It looks like you are running into this problem here: Each GROUP BY expression must contain at least one column that is not an outer reference
As the answer points out, grouping by a constant literal is pointless as it is the same for all results. Count(*) will return the same result as Count(*) with a GROUP BY.
If this is just test code and you plan on using a CASE statement (with different values) in place of the string literal, you may have better luck.
Yes, T-SQL is Microsoft SQL Server's flavor of SQL.
The query below is working fine:
SELECT *
FROM OPENQUERY(DS_64, 'SELECT TOP 1 * FROM "workforce"."sales" WHERE ORDER_UPDATED > ''2020-07-24 14:03:23'' ')
When I'm using ORDER_CREATED in place of ORDER_UPDATED, I'm getting the below error:
OLE DB provider "MSDASQL" for linked server "DS_64" returned message
"[SAP AG][LIBODBCHDB DLL][HDBODBC] General error;314 numeric overflow:
search table error: [6944] exception 70006944: AttributeEngine:
overflow in numeric calculation
Any help is going to be highly appreciated. Thanks in advance :)
Below is the query that is giving the above error:
SELECT *
FROM OPENQUERY(DS_64, 'SELECT TOP 1 * FROM "workforce"."sales" WHERE ORDER_CREATED > ''2020-07-24 14:03:23'' ')
I think the syntax for top is limited in the HANA universe. Also, check the datatype HANA is actually using from HANA Studio.
In SQL Server 2016 I have a stored procedure. In this SP I want to get all data from a view from a linked server (PostgreSQL) by using the following statement:
INSERT INTO myTable
SELECT Field1,
Field2,
Field3,
...
FROM OPENQUERY(myServer, 'SELECT * FROM myDatabase.mySchema.myView')
When I use it like this, I'm getting the following error message after a few minutes:
Out of memory while reading tuples.
I changed the SELECT statement in OPENQUERY to get only the first 1000000 rows which worked fine:
SELECT * FROM myDatabase.mySchema.myView ORDER BY Field1 LIMIT 1000000
Now I am unsure what the most practical way to get all data would be. I could insert the first 1000000 rows and then insert the next 1000000 using OFFSET. But I don't think this would be a nice solution as I don't know what the total number of rows is. A loop would be another way but I really don't know if this would be the easiest way to achieve what I want.
Any help would be appreciated.
i think you are using odbc driver for creating linked sever .It is issue with psqlODBC driver memory configuration .
You change odbc driver setting opening your data sources
Press "Configure", then in the opened data source details
"Options" section select "Datasource"
and in the opened window check the "use declare/fetch".
Select to Sybase table from SQL Server (by LinkedServer) getting error "The OLE DB provider "MSDASQL" for linked server "XXX" supplied inconsistent metadata for a column. The column "XXXX" (compile-time ordinal 1) of object "db.schema.table" was reported to have a "DBCOLUMNFLAGS_ISFIXEDLENGTH" of 16
Query: Select * from [Server].[db].[schema].[table]
Finally after searching some time in the web found the answer, when makes a query on a table having a nullable CHAR column gives the error...
So the solution was create a View in Sybase where I make an ISNULL Validation for the specific column, and from the SQL Server query the View instead the table.
Query: Select * from [Server].[db].[schema].[view]
Source: http://www.dbainfo.net/wp-content/uploads/CR/sdk_17.htm
When obtaining an image grabde with sql server linked servers from PostgreSQL, I get the following error: OLE DB provider 'MSDASQL' for linked server 'bd_acceso_ruisegip' returned data that does not match expected data length for column '[MSDASQL] . fot_imagen '. The data length (maximum) expected is 255 and the data returned is 38471.
Don't know if you were dealing with a bytea column but I was having the same problem. Found the answer in the configuring of the postrgres ODBC system dsn. Under the Options/Datasource-page 2 there is a option for bytea as LO. Clicked that and now it works like a champ.
I found a similar issue when replicating some Forum data from PostgreSQL to MSSQL, using the PostgreSQL 64-bit driver and a Linked Server (.
When I coded like this:...
select * into Post from OpenQuery(PostgreSQL_Test1, 'select * From public.post')
... the MSSQL table defaulted to a column size of nvarchar(4000).
My fix: First, run it once with a small limit on the number of rows copied:
select * into Post from OpenQuery(PostgreSQL_Test1, 'select * From public.post limit 10')
Next, right-click on the local Post table. Choose "Script table as drop and create"
In the create script, replace the size of the offending column with VARCHAR(MAX)
Next, create the table.
Then use:
Insert Post select * from OpenQuery(PostgreSQL_Test1, 'select * From public.post')
Hope that helps.
Your mileage may vary.