How does partition in sybase works? - sybase

I am trying to Create a partitioned table in Sybase IQ
create table demo(id varchar(20),name varchar(20),city varchar(20))
partition by city
It throws error
Error: Syntax error near 'city' on line 2 (State:37000, Native Code: FFFFFF7D)
How to overwrite a particular partition in Sybase while inserting the records for that existing partition.

Your syntax is incorrect.
Syntax is:
...
partition by range (<column>)
(<partition-name-1> values <= (<ptn-max-value>), ...more partitions...)

Related

partitioning an existing Table and using Like or Where clause with it

I'm trying to partition an existing table but I need to use Where or like clause.
The problem is I can't partition it cause every query I wrote, I get an error.
My last code is:
select *
into agg partition by range (subscriberid)
(subscriberid values LIKE '%42' on seg1)
from ncs_sub_unsub;
I've tried a lot of sources to get the answer how I can use a WHERE clause and the partition
Note: the Where and like clause is an initial part of the partitioning
My table : ncs_sub_unsub
The uniqure identifier is : subscriberid

TABLE(RESULT_SCAN()) is behaving differently for Clustered Inserts

I am trying to fetch record counts from table(result_scan()) for clustered tables.
Table - 1 : clustered by 1 key
select sum("number of rows inserted") from TABLE(RESULT_SCAN(query_id)). This worked and gave back record count.
Table -2 : clustered by 2 keys.
Could not execute the record count query:
select sum("number of rows inserted") from TABLE(RESULT_SCAN(query_id)). Error Message obtained is 000904 (42000): 01929f09-01a8-3a2c-0000-54ad005bcfc2: SQL compilation error: error line 1 at position 11
invalid identifier '"number of rows inserted"'
Not sure why the same query works in one scenario and throws invalid identifier in another?
As I see, the COPY command does not return the "number of rows inserted" column. If you want to get the number of rows inserted by COPY command, you should sum the rows_loaded column:
select sum("rows_loaded") from TABLE(RESULT_SCAN());
Please check: https://docs.snowflake.net/manuals/sql-reference/sql/copy-into-table.html#output

Violation of PRIMARY KEY constraint 'PK_readytoship'. Cannot insert duplicate key in object 'readytoship'

Our SQL systems administrator walk out on this issue so it was dumped in my lap. I'm Not a wealth of knowledge on SQL but I get by. He has SQL 2012 ported to SQL2000 server and we got a job query part failing. I pasted the job query into SSMS and got a Violation KEY constraint. Query and error below. Any help is appreciated. Thanks.
INSERT INTO [dbo].[readytoship]
([delivery]
,[so]
,[netvalue]
,[createdate]
,[resonorder]
,[reason]
,[shipto]
,[insertdate]
,[delta]
,[shpt])
(select vl06cst.delivery,
vl06cst.salesorder,
netvalue as netvalue,
createdate,
case when vl06cst.insertdate<maxdte and vl06cst.insertdate>mindte then 'P'
when vl06cst.insertdate=mindte and vl06cst.insertdate<maxdte then 'O'
else 'C' end as resonord,resoncode,
shiptoparty, vl06cst.insertdate, dbo.ElapsedTime(createdate,getdate()) as delta,shippoint
from vl06cst join vbak on right(vbak.salesorder,9)=vl06cst.salesorder join vl06minmaxdte on vl06cst.delivery=vl06minmaxdte.delivery
where isnumeric(vbak.salesorder)>0
group by vl06cst.delivery,vl06cst.salesorder,createdate, resoncode, shiptoparty,vl06cst.insertdate, netvalue,resonorder,mindte,maxdte,shippoint)
Result:
Msg 2627, Level 14, State 1, Line 1
Violation of PRIMARY KEY constraint 'PK_readytoship'. Cannot insert duplicate key in object 'readytoship'.
The statement has been terminated.
(0 row(s) affected)
To maintain the integrity of the data, you cannot insert duplicate data into your table, reading your code I believe that you can use this where to solve it.
where isnumeric(vbak.salesorder)>0 AND
NOT EXISTS (SELECT 1 FROM [dbo].[readytoship] A where vl06cst.delivery=A.delivery)
You need to understand you your code is trying to insert an existent data on the table readytoship and is this is the best solution

Bad int8 external representation "6*725" in Netezza

I am getting an error like "Bad int8 external representation "6*725" " in netezza while executing a stored procedure . This stored procedure takes data from a table does some transformations and load into another table.
Can any one please help me .
Thanks,
Brajendra
FYI: May be multiple answers to this question because do not have the query that you ran to get the error.
If you did a direct INSERT command like this, the order of the columns of the table from the select clause DO NOT match the order of the columns of the table from the insert clause. Most database management systems doesn't care what the order is, but Netezza does. The fact that it threw the "Bad int8" just means the first column it couldn't match in the select clause has that data type, and the data type in the insert clause has a different data type.
INSERT INTO DB1..TABLE1
SELECT * FROM DB1..TABLE2;
You can fix with one of two methods. Either change the order of the columns by dropping and recreating the table. Or use explicit column names in the INSERT INTO/SELECT command.

T-SQL - how to insert while looping through a table

I have a table that holds organization data. I also have a new table that is going to hold info about shipping containers.
As an initial test I want to populate the new Shipping_Containers table by giving one container to each organization.
So I thought about getting the organization ids and looping through them and doing an insert into Shipping_Containers for each organization id, something like this:
select * into #orgs from Organization_1
while (select id from #orgs ) IS NOT NULL
begin
insert into Shipping_Containers (name, org)
values('test_name', id)
end
I know there is probably a lot wrong with that but firstly it is giving this error:
Msg 207, Level 16, State 1, Line 4
Invalid column name 'id'.
I'm using SQL Server 2008 R2 and I'm new to T-SQL so any guidance here would be appreciated, thanks.
Try
INSERT INTO Shipping_Containers (name, org)
SELECT 'test_name', id
FROM Organization_1

Resources