Delete Fails using ODBC in SSIS - sql-server

I changed an Execute SQL Task targeting my default, local SQL Server instance from OLE DB to ODBC. The SQL is
delete from tablename
The ODBC version works fine when the table has records but fails when the table is empty.
I thought about using the result set of another SQL Task to populate a variable but that would not work. Reading this SO article Delete statement fails when called from SSIS identified the source of the problem (ODBC version), but it still didn't provide the answer. Other web articles suggested no workaround.
Are there any other methods or approaches to conditionally call the delete only if the table is not empty?.

It occurred to me to just use T-SQL to solve the problem. I used a T-SQL conditional statement which works fine. The ODBC SQL Task succeeds whether or not the table is empty.
if 0 < (select count(1) from tablename)
delete from tablename

Related

Simple query generates Error 3078 "The Microsoft Jet database engine cannot find the input table or query"

Any suggestions how to restructure this simple query?
Hitting a SQL Server Database using DAO via VB6 (updated old code to work with new database) and somehow this query in one of the apps is giving fits.
Select I.sType, Count(I.BarcodeID) AS CountOfID
FROM (SELECT DISTINCT sType, BarcodeID From [Ready]) as I
GROUP BY I.sType
ORDER BY sType
I've pasted the query into SQL Enterprise Manager and it runs just fine as expected. It worked fine hitting the original Access DB. But somehow the DAO via ODBC hitting the SQL Server is generating:
"The Microsoft Jet database engine cannot find the input table or query"
Things I've tried:
Removing the ()
Removing "as I" and "I." notation.
Brackets around [Ready] and without (thinking it might be reserved
keyword).
Confirmed that the connection is to the ODBC for Sql Server (this connection is used for other queries too.
Checked SQL profiling tool and the query is making it to the server (edited, I was checking the wrong tool on SQL Express)
EDIT: just to sate everyone's concern that I'm not really hitting SQL Server, I edited the SQL command to an even simpler
SELECT DISTINCT sType, BarcodeID From [Ready]
and it works correctly ON the same connection, so the connection is 100% confirmed to be SQL Server, the error message is in error (reported "Access").
So the problem is with no doubt the query FROM a query.
UPDATE:
Definitely confirmed my suspicions that the query, albeit a normal one, is not working with ADO-> ODBC-> Sql Server.
The first step SQL is doing is trying to validate the columns, etc.. of the "from" table (which in this case is not a table, but a query itself).
When I run a basic SELECT DISTINCT sType, BarcodeID From [Ready] SQL checks the columns, keys, indexes, etc of the table called "Ready" (exec sp_special_columns N'Ready',NULL,NULL,N'V',N'T',N'U'), then proceeds to return the results.
When I use a subquery, SQL is firing the same check on the table def, but for a table called SELECT DISTINCT sType, BarcodeID From [Ready] which of course does not exist and it returns an error (exec sp_special_columns N'SELECT DISTINCT sType, BarcodeID From [Ready]',NULL,NULL,N'V',N'T',N'U'). VB6/ADO is reporting correctly that SQL says the table is not found. So apparently this query from a query stumps the capabilities of ADO->ODBC...
since the issue is clearly the Select FROM (Select From) structure of querying a query being incompatible with ADO->ODBC->SQL Server, my solution was simply to make the subquery a view in SQL and alter the query to select from that.

How to copy data from a view of one server into the database table of another server in a SQL server database?

how can i copy data from a view of one server into the database table of another server in a SQL server database without using linked servers method.
I tried using the code:
SELECT [LogEntryID]
,[TimeStamp]
Into [server-2].[database1].[dbo].[table1]
FROM [server-1].[database1].[dbo].[view_1]
I recieve the error " The object name 'server-2.database1.dbo.table1' contains more than the maximum number of prefixes. The maximum is 2.
The copying statement i am using in a groovy code. But for first i am trying it in a query if it works.
You can use opendatasource instead of linked server
insert DestinationTable
select * from opendatasource('SQLOLEDB', 'Server=SourceServer;User Id=Username;Password=Password;').SourceDb.Schema.SourceTable;
OPENDATASOURCE

No column information was returned by the SQL command. SSDT

I'm attempting to create an update query in SSDT. I'm getting
Unable to parse query text.
The query is:
UPDATE CustOrderWithDisp
SET YARDS = CustOrderWithDisp.QUANTITY * Lkp_TestCodes.[Test_GALS] * 0.00495113
FROM CustOrderWithDisp
INNER JOIN Lkp_TestCodes
ON CustOrderWithDisp.TEST_CODE = Lkp_TestCodes.[SVC CODE]
But if I actually run the query, it works.
I want to use this query in an SSIS package. When I put this query in an OLEDB Source, i get...
The component reported the following warnings:
Error at qry03_CalculateYards [OLE DB Source [33]]: No column information was returned by the SQL command.
I'm a novice at this, so be gentle. Your help is greatly appreciated!
Error at qry03_CalculateYards [OLE DB Source [33]]: No column information was returned by the SQL command.
You are receiving this message because OLEDB Source is a DataFlow Task component, it is used to read data from an Table or SQL Command through an OLEDB Connection.
The OLE DB source extracts data from a variety of OLE DB-compliant relational databases by using a database table, a view, or an SQL command. For example, the OLE DB source can extract data from tables in Microsoft Office Access or SQL Server databases.
You don't have to put this query in an OLEDB Source, you have to use an Execute SQL Task and write this query in the SQL Command property.
For UPDATE queries you have to use Execute SQL Task (in the Control Flow level, no in the DataFlow)
The Execute SQL task runs SQL statements or stored procedures from a package. The task can contain either a single SQL statement or multiple SQL statements that run sequentially.
References
Execute SQL Task
OLEDB Source

How to check that MSSQL trigger is runnable?

How can I check that target trigger is runnable?
In Oracle I can simple select it from user_object table:
SELECT status FROM user_objects WHERE OBJECT_TYPE = 'TRIGGER' and object_name='trigger_name'
Can I do something similar in MSSQL?
Solution: Find broken objects in SQL Server
There is no equivalent validation in SQL Server regarding the Oracle behavior described in the comments on the question. If the Trigger exists and is enabled, it is runnable. It might error, but SQL Server will at least attempt execution.

linked server problem at sql server while connecting to oracle dbms

I have created a linked-server definition according to the article at :
http://www.ideaexcursion.com/2009/01/05/connecting-to-oracle-from-sql-server/
My aim is to transfer rows to tables at Oracle 11gR2.
After creating linked server, whenever I try to select a table using a query like :
SELECT *
FROM [192.168.1.188]..[ESIPARIS].[T_ERROR_LOG]
I get the error below :
Msg 7356, Level 16, State 1, Line 1
The OLE DB provider "OraOLEDB.Oracle" for linked server "192.168.1.188"
supplied inconsistent metadata for a column. The column "EVENT_OBJECT"
(compile-time ordinal 2) of object ""ESIPARIS"."T_ERROR_LOG"" was reported
to have a "LENGTH" of 50 at compile time and 100 at run time.
One more thing is that it duplicates field names whenever a select statment is prepared by "Sql Server Management Studio", some fields are duplicated as below :
SELECT [EVENT_DATE]
,[EVENT_DATE]
,[EVENT_DATE]
,[EVENT_DATE]
,[EVENT_OBJECT]
,[EVENT_OBJECT]
,[EVENT_OBJECT]
,[EVENT_OBJECT]
,[MESSAGE]
,[MESSAGE]
,[MESSAGE]
,[MESSAGE]
,[EVENT_ID]
FROM [192.168.1.188]..[ESIPARIS].[T_ERROR_LOG]
I would be very happy to hear from you about any ideas, thank you for your concern,
Best Regards,
Kayhan YÜKSEL
There are a number of scenarios which might throw this error:
your distributed query in SQL Server references a view with an underlying table in Oracle with a primary key column created in a certain way, Find out more
there's a bug when the querying a view with numeric columns. Find out more
it may be a problem with driver incompatibility, such as using the MS OleDB driver instead of the one Oracle provides.
If it isn't the driver one possible workaround is to use OPENQUERY. Otherwise. this support note contains general information on troubleshooting linked server and Oracle.
(This problem is a fairly generic one, so it turned out that the actual resolution was none of the things I suggested. I'm incorporating #kayhanyüksel's solution in the body of this response for the sake of completeness.)
Solved it with changes at listener and tnsnames. We are now able to connect from SQL Server to Oracle 11gR2 (running on 64 bit Red Hat Enterprise Linux 5.4 ) and vice versa. Documents followed are
- Making a Connection from Oracle to SQL Server
- The Oracle Gateways documentation
I had the same problem: The column ...... was reported
to have a "LENGTH" of 50 at compile time and 100 at run time. and duplicate column names when selected.
while i was trying to run a query in MS SQL from an ORACLE 11g database
I used the follownig type of query and it worked !
DECLARE #TSQL varchar(8000)
SELECT #TSQL = 'SELECT * FROM OPENQUERY(MyLinkedServer,''SELECT * FROM TableName'')'
EXEC (#TSQL)
where MyLinkedServer is the name of the linked server and
TableName is the name of the table.
here you have the link to the article that helped me: http://support.microsoft.com/kb/314520
Old thread but it may be useful to someone.
When I recently encountered this error, using as provider the MS OleDB driver instead of the Oracle OleDB provider solved the problem.
I have the same issue with 11g client but it was disappeared with client version 12 which works for me is using OPENQUERY and to_char with the field that makes problem.
I confirm that SQL management studio (no matter what version) gives many duplicated field. The only installing of last driver version we can have consistent queries. I hope it can be useful for you!

Resources