OUTPUT TO FILE LOCAL SYBASE IQ 16 - sql

I'm trying to write my existing tables to files and save it locally.
I'm using T-SQL with SQuirrel JDBC Connection to Sybase
I tried the following Code to write results into a file:
SELECT * FROM date_dimension;
OUTPUT TO "C:\Users\temp\output.txt" FORMAT ASCII;
I dont know why it doesn't work but I get a Syntax error while trying this.
Error: SQL Anywhere Error -131: Syntax error near 'OUTPUT' on line 1
SQLState: 42W04
ErrorCode: 102
Can someone see a mistake in the code? Is there another way to write into file from Sybase IQ?
I'm new to all this Tools and I'm sry for such a question
Please help me :)
CREATE TABLE DATE_DIMENSION
( [DateKey] INT primary key,
[Date] DATETIME,
[FullDateUK] CHAR(10), -- Date in dd-MM-yyyy format
[FullDateUSA] CHAR(10),-- Date in MM-dd-yyyy format
}

That should work, your syntax is correct, can you provide the ddl of the table?
Edit: try this select statement:
select DateKey,("Date"),FullDateUK,FullDateUSA from DATE_DIMENSION;
OUTPUT TO "C:\Users\temp\output.txt" FORMAT ASCII;

Related

Failed to execute query. Error: String or binary data would be truncated in table xdbo.user_info', column 'uid'

I have problem inserting values in my SQL server database on Azure, I am getting the following error:
Failed to execute query. Error: String or binary data would be truncated in table 'dummy_app.dbo.user_info', column 'uid'. Truncated value: 'u'.
The statement has been terminated.
I don't understand where I am wrong, I just created the server, and I am trying to experiment but cant fix this.
if not exists (select * from sysobjects where name='user_info' and xtype='U')
create table user_info (
uid varchar unique,
name varchar,
email varchar
)
go;
INSERT INTO dbo.user_info(uid, name, email) VALUES('uids', 'name', 'email') go;
Creating the table works fine, the only thing that doesn't work is the second command INSERT
I suspect that the reason is that you haven't defined a lenght for varchar and it defaults to 1 as length. Therefore your value gets truncated.
Set a varchar length to something like varchar(200) and you should be good to go.
This looks like the fact that the CREATE portion of your procedure for the table doesn't include a length of varchar, so you'd have to specify a length such as varchar(50) since the default is 1. Refer to the official MS docs in the link, in the remarks.
docs.miscrosoft.com
Also, here is the syntax for the CREATE TABLE in Azure which might be helpful as well.
Syntax of Azure CREATE TABLE

Sqlalchemy Teradata ODBC 17.00 to_sql QVCI error CAST CLOB type to DATE

I am trying to use pandas to_sql to an existing table in Teradata database but I got this QVCI error. After some research online, I upgraded my ODBC driver to 17.00 but I still get the same error.
Existing Table:
I am using sqlalchemy_teradata
Here is the code:
a_df.to_sql(name='TEST_LA_TEMP', con=engine, schema='DB', if_exists='replace', index=False)
I then tried to specify the types but got the same error.
from sqlalchemy.types import INTEGER, VARCHAR, Date
a_df.head()
a_df.to_sql(name='TEST_LA_TEMP', con=engine_ldap, schema='DB', if_exists='replace', index=False
, dtype={'id': INTEGER,
'p_name': VARCHAR(20),
'dept': VARCHAR(20),
'update_date': Date})
ERROR:
DatabaseError: (teradata.api.DatabaseError) (9719, '[HY000] [Teradata][ODBC Teradata Driver][Teradata Database](-9719)QVCI feature is disabled.')
[SQL: SELECT *
FROM dbc.ColumnsQV
WHERE DatabaseName (NOT CASESPECIFIC) = CAST(? as VARCHAR(128)) (NOT CASESPECIFIC) AND TableName=?]
[parameters: ('DB', 'TEST_LA_TEMP')]
When I use the same code to import to an NEW (non-existing) table, it works fine but returns CLOB as datatype for most columns
I then tried to CAST CLOB Types to the correct Types but it said CLOBs can only be converted to CHAR TO VARCHAR missing my update_date column.
I can get it working if I use if_exists='append' instead, and then drop and create table again. but I still want to understand why and how to resolve these errors.
Questions:
What is the syntax to enable QVCI directly for Teradata?
Is there a way to CAST CLOB to DATE? How?
Why if_exists='replace' depends on QVCI but not if_exists='append'?
Thank you!

Error While updating Table using Linked Server

I am trying to update a table in a server(ServerA) using a linked share connection from ServerB and i Got the below Error
The OLE DB provider "SQLNCLI10" for linked server "ServerA" could not
UPDATE table "[ServerA].[MyDb].[dbo].[tbl_name]" because of column
"CreateDt". Conversion failed because the data value overflowed the
data type used by the provider.
This is the query I Used :
update [ServerA].[MyDb].[dbo].[tbl_name]
set transfer_fl = 1,
CreateDt = getdate()
where transfer_fl<>'1'
the column CreateDt is of data type smalldatetime and it already has a value in it.
Can somebody give explain me why this happens.
This is a bug in SQL 2008/R2.
https://connect.microsoft.com/SQLServer/feedback/details/430745/sql-server-2008-unexpected-behavior-when-inserting-datetime-value-in-smalldatetime-column-on-a-linked-server
Unluckily it is marked as won't fix and you would have to do an explicit conversion.
GETDATE (Transact-SQL)
Sintaxis
GETDATE ( )
Tipo de valor devuelto
datetime
no smalldatetime
Here is more detail explain of the SQL Server Error Messages - Msg 298

Syntax error while converting varchar to numeric in sql

I want to convert a varchar to numeric, I looked aroud and found SELECT CAST. I tried to use it like this this:
SELECT CAST(`Elo` AS INT) FROM Table `Rankings`;
However, I get a syntax error. Is there anything wrong?
Remove the Table keyword from your query.
SELECT CAST(`Elo` AS INT) FROM `Rankings`;

SQL Server Alter Table Query (Incorrect Syntax)

I'm stumped, and I know this is probably something very simple. I am trying to add two columns to an existing table.
I am receiving the following syntax error:
Incorrect syntax near 'PublishedDate' Expecting '(', or SELECT.
Here is my SQL:
ALTER TABLE my_table ADD (PublishedDate DATETIME, UnpublishedDate DATETIME)
Try without the parentheses:
ALTER TABLE my_table
ADD PublishedDate DATETIME, UnpublishedDate DATETIME
Here is a sqlfiddle with a demo for you to try.