How can I insert multiple records with a single INSERT statement in Sybase ASE - sap-ase

This feature is available in MySQL as shown in this post and according to the Sybase documentation it should also be supported, however Sybase don't provide a worked example so you have to interpret the following:
Syntax 1 Insert a single row, or multiple rows, with the specified expression column values. Multiple rows, if specified, are delimited by additional parentheses
So I interpret "additional parentheses" as expecting the following code to work
create table #tmp_codes (
code varchar(12) NULL
)
insert into #tmp_codes (code)
values
('AAA'),
('BBB'),
('CCC')
However it errors with
Incorrect syntax near ',' on line 7
I'm using Sybase ASE 15 and cannot see any reference to inserting multiple rows on this support page for the INSERT statement
Is this feature available in Sybase?

Your first Sybase doc link is ASA not ASE documentation.
In ASE you can insert multiple rows only with insert - select statement.

This seems long ago asked question but may be useful for reference.
Create a Text file with multiple Rows.
Run this command from Sybase ASE:
INPUT INTO TableName
FROM FilePath\FileName FORMAT TEXT
Example:
INPUT INTO TempTable FROM c:\test.txt FORMAT TEXT

Related

How to copy data from ADF to Synapse with special character("Ã") in one of the fields without errors or record rejection

I have a scenario where I copy data from Azure storage account(CSV - Pipe delimited source file) to Azure Synapse using ADF Copy utility. However the pipeline is failing because three of the records has special character "Ã" in one of the character field. Tried different encodings UTF-8,UTF-16 and Windows-1252, but none of them resolved my issue. I have also tried direct Copy utility(Copy into "") within Azure Synapse and getting the same error. I am able to manually insert those three records using "Insert into " statement.
Is there a better way to handle this without Manual inserts through something like doing pre conversion of that character before copy or through any available settings in ADF?
Please re-check the format settings for the source csv dataset as given in this Microsoft Documentation.
I reproduced this in my environment, and I am able to copy the csv data with special characters into Synapse with default UTF-8 encoding.
This is my source csv with special characters:
I have created a table named mytable in Synapse.
create table mytable (
firstname VARCHAR(32),
lastname VARCHAR(32)
)
WITH
(
DISTRIBUTION = HASH (firstname),
CLUSTERED COLUMNSTORE INDEX
)
GO
In the source give the format settings as per the above documentation.
Here I have used copy command to copy. If you want to create table automatically, you can enable it in the sink.
Copied data in Synapse table:

Add values to a Multiple Metadata column via SQL

I am trying to add multiple values to a multiple metadata column via SQL using a third party migration tool (Layer 2), but it only works when I add one value as explained below.
I have written some testing code like this in SQL
Select …
,'Qualifications;BA'
From
(Where Qualifications is the termset and BA and BSc are the terms)
And it works with just the one value with the SQL shown above.
However, I want this
To try to do this, I have amended the SQL like so
,'Qualifications;BA;BSC'
,'Qualifications;BA; Qualifications;Bsc '
,'Qualifications;[BA];[BSC]'
But sharepoint does not attempt the format and wont add any values
The error I get back from the software is
Does anyone know what the SQL should be to make this work, if possible?
Thanks
Add a pipe e.g. '|' to the list
'Qualifications;BSc|BA'

How do I remove characters from a query field that cause Excel to interpret the field as more than one column or as a function

I am stuck having to query a SQL Server database that is mimicking SQL server 2000 database and no way around it.
I have a large result set of 5 fields. The last field is a memo field. The result set is so large in SSMS 2012 that I cannot select them all with headers. So I have to save to Excel csv format. In doing so it interprets data in the 5th field as either a function (“-“, “+”, “(space) –“, “(space)+”, etc at the beginning) or as multiple columns for various reasons.
So far I have
replace(ltrim(rtrim(memo)), ',', ' ') as Memo
This, of course, trims beginning and end and replaces commas with spaces. I do not want to have to build nested replaces unless I must. This is for a large audit report that is not run often so I can, if need be, use a function.
Is there a good way to make a field like this compliant with Excel so that Excel will just keep that field as one column? I would appreciate any insight.
It seems that the correct method is to append double quotes to the beginning and the end of the field value returned in the query. As I am having to right-click and output to Excel this methods works and Excel does not misinterpret the intent.

Inserting data into TEXT type column in Informix

How do I insert data into a columm with the type TEXT in Informix via SQL. If there are two other columns that I also want to insert/update - is the only way to save it in a file and LOAD it?
Or if I want to do do via SQL statements - can you give the syntax?
See my question: Consistent method of inserting TEXT column to Informix database using JDBC and ODBC
It is easy with JDBC and PreparedStatement. ODBC works little different but is able to insert string with simple SQL INSERT (without preparing).
The load command works, and you can also use ESQL/C to do it (it is mentioned in this answer that you might already found).
About doing it in a simple insert,
You can use the VALUES clause to insert a value, but the only value that you can give that column is null. However, you can use the SELECT form of the INSERT statement to copy a TEXT or value from another table.
You can see here the docs for Text data type.

Adding columns to a sybase table with unique auto_identity index option

I've inherited a Sybase database that has the 'unique auto_identity index' option enabled on it. As part of an upgrade process I need to add a few extra columns to the tables in this database i.e.
alter table mytable add <newcol> float default -1 not null
When I try to do this I get the follow error:
Column names in each table must be unique, column name SYB_IDENTITY_COL in table #syb__altab....... is specifed more than once
Is it possible to add columns to a table with this property enabled?
Update 1:
I created the following test that replicates the problem:
use master
sp_dboption 'esmdb', 'unique auto_identity indexoption',true
use esmdb
create table test_unique_ids (test_col char)
alter table test_unique_ids add new_col float default -1 not null
The alter table command here produces the error. (Have tried this on ASE 15/Solaris and 15.5/Windows)
Update 2:
This is a bug in the Sybase dbisql interface, which the client tools Sybase Central and Interactive SQL use to access the database and it only appears to affect tables with the 'unique auto_identity index' option enabled.
To work around the problem use a different SQL client (via JDBC for example) to connect to the database or use isql on the command line.
Should be no problem to ALTER TABLE with such columns; the err msg indicates the problem regards something else. I need to see the CREATE TABLE DDL.
Even if we can't ALTER TABLE, which we will try first, there are several work-arounds.
Responses
Hah! Internal Sybase error. Open a TechSupport case.
Workaround:
Make sure you get jthe the exact DDL. sp_help . Note the IDENTITY columns and indices.
Create a staging table, exactly the same. Use the DDL from (1). Exclude the Indices.
INSERT new_table SELECT old_table. If the table is large, break it into batches of 1000 rows per batch.
Now create the Indices.
If the table is very large, AND time is an issue, then use bcp. You need to research that first, I am happy to answer questions afterwards.
When I ran your sample code I first get the error:
The 'select into' database option is not enabled for database 'mydb'. ALTER TABLE with data copy cannot be done. Set the 'select into' database option and re-run
This is no doubt because the data within your table needs copying out because the new column is not null. This will use tempdb I think, and the error message you've posted refers to a temp table. Is it possible that this dboption has been accidentally enabled for the tempdb?
It's a bit of a shot in the dark, as I only have 12.5 to test on here, and it works for me. Or it could be a bug.

Resources