Export file using Sybase Event - sql

I'm trying to output a file to a shared folder, I can make the output but I can't run it on a event/Stored Procedure.
The code snippet that I have to the output is this:
BEGIN
select * from table1; output to 'c:\\teste.txt' format text with COLUMN names
END
But when I include this in a event, the sybase gives me this error.
[Sybase][ODBC Driver][SQL Anywhere]Syntax error near 'output' on line 2
SQLCODE: -131
SQLSTATE: 42000
SQL Statement: ALTER EVENT "dba"."Export" HANDLER BEGIN
select * from table1; output to 'c:\teste.txt' format text with format text with COLUMN names
END
I am using Sybase Central with sql anywhere 12

Use the unload table statment in Event.
"Output to..." will onsly work in DBISQL
Example:
UNLOAD SELECT field1, field2 from table1 to 'c:\temptest.csv QUOTES OFF DELIMITED BY ';';

Related

can't insert mmddyy10. format proc sql

I have a table with column as_of_date that is formatted as MMDDYY10. in SAS 7.1
proc sql;
INSERT INTO mytable (as_of_date)
VALUES (12/31/2016);
run;
and I get the following error:
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,
a missing value, ), +, ',', -, MISSING, NULL, USER.
ERROR 200-322: The symbol is not recognized and will be ignored.
Note: if I change the value to 12/31/16 it still does not work. If I put quotes around it ('12/31/2016') I get the error:
ERROR: Value 1 of VALUES clause 1 does not match the data type of the corresponding column in the object-item list (in the SELECT
clause).
If I insert it without slashes (12312016) it is inserted without errors as ********
You need to use the DDMMMYYYY format within quotes and the d modifier:
proc sql noprint;
INSERT INTO mytable (as_of_date)
VALUES ("31dec2016"d);
quit;
Another way to look at it is SAS is looking for the numeric value underneath a date format. You can check the actual value and use the following code to get the same result:
data check;
date = "31dec2016"d;
run;
proc sql noprint;
INSERT INTO mytable (as_of_date)
VALUES (20819);
quit;

Invalid table name while bulk insert in oracle

I am trying to insert values into Oracle table using Bulk Insert query but getting below error
ORA-00903: invalid table name
00903. 00000 - "invalid table name"
*Cause:
*Action:
Error at Line: 4 Column: 5
Here is my query
BULK INSERT TEST1.STUDENT
FROM 'C:\Users\Alan\Desktop\STUDENT.txt'
WITH
(
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
);
Why is this error coming. Is there some issue with query? Please help. Thanks
Update
I changed by file format to CSV and wrote below query
LOAD DATA
INFILE 'C:\Users\Alan\Desktop\STUDENT.csv'
INTO TABLE TEST1.STUDENT
FIELDS TERMINATED BY ","
(ID,
NAME);
but above query is giving
ORA-00928: missing SELECT keyword
00928. 00000 - "missing SELECT keyword"
*Cause:
*Action:
Error at Line: 16 Column: 2
What is wrong in the above syntax?
This is not Oracle syntax at all. If you need to load data from file to table please use either SQLoader or External table
Some documentation about External table and SQLoader
If you're using SQLDeveloper you can also use import facility.
Please also have a look on that thread.
[EDIT}
LOAD DATA
INFILE 'C:\Users\Alan\Desktop\STUDENT.csv'
INTO TABLE TEST1.STUDENT
FIELDS TERMINATED BY ","
(ID,
NAME);
This is not a query. This is content of control file. Please save it to file load.csv then run cmd (or shell if yuo're on Linux) and type:
sqlldr user/pass control=load.ctl
Some examples you can find here.

OUTPUT TO FILE LOCAL SYBASE IQ 16

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;

How to insert special characters to a table row via SQL Editor

I have a table in my SQL Server database with a column of type nvarchar(50);
I tried to do this:
Right click on my table
Selecting "Edit 200 first rows"
Typing in that column 'a'
I get an error like this:
Error source: .Net SqlClient Data Provider.
Error message: Incorrect syntax near 'a'.
Correct the errors and retry".
Why do I get this error message and how can I fix this?
I have used aqua data studio and tested this it is allowing me.
my result:::
id testc
----- ---------
1 'asdfasd'
If you want to use it thrugh .net then while passing the string add the escape sequences. suppose if you are sending "'"--single quote.. then send I have used and tested this it like "\'" is allowing me.
refer below link:::
http://www.codeproject.com/Questions/157918/How-can-I-insert-a-special-character-in-sql-server
I have had the same error.
I want to insert a value I am Nam 'ABC' into MyTable at field Description as following SQL statement
Insert Into table MyTable (Description) values('I am Nam 'ABC'');
Once Insert command executed the error occur immediately
Incorrect syntax near 'ABC'.
Note that the reason why is SQL will understand character " ' " which before ABC belongs to character
" ' " before I, and one after ABC belongs to " ' " at the end. As a result ABC does not belong to SQL
statement anymore therefore it makes a break of statement.
Here is my solution:
I added two single quotes for each side of ABC
Insert Into table MyTable (Description) values('I am Nam ' 'ABC' ' ');

oracle query returns 0 records when args passed

When I run an sql like this:
select * from tbl_emp where emp_name like '%%'
It gives me all records.
When I run it like this:
select * from tbl_emp where emp_name like : arg_emp_name
Then execute the query, then pass arg_emp_name as '%%', it returns 0 records.
Why is this behavior?
Thank you.
That should work fine. For example the following returns the same number of records as no where clause
EXEC :arg_emp_name := '%%';
SELECT * FROM ALL_TABLES WHERE TABLE_NAME LIKE :arg_emp_name
If you add more to the string
EXEC :arg_emp_name := '%ABC%';
SELECT * FROM ALL_TABLES WHERE TABLE_NAME LIKE :arg_emp_name
only Tables with ABC in their name are returned
However I would note that there's no space between : and arg_emp_name
Having that space there causes the error
Error starting at line 4 in command:
SELECT * FROM ALL_TABLES WHERE TABLE_NAME LIKE : arg_emp_name
Error report:
SQL Error: ORA-01008: not all variables bound
01008. 00000 - "not all variables bound"
*Cause:
*Action:
NEW ANSWER:-
As per the comments obtained for the answer, it is clear that the oracle does not see any difference between the literal and the binding variable values. The meaning does not change as I had mentioned in my old answer. The answer from #Conard seems logical.
OLD ANSWER:-
When you pass the '%%' as an argument, it is literally taken as those string and they lose out on special meaning which they have when used in the query.
It means, the query will search your column for data containing '%%' instead of treating it as a LIKE. Hence you get 0 records.