Solved

SQL PERVASIVE , INSERT INTO ,  WITH A KEY  BEING identity- type in VB6

Posted on 2011-03-15
6
1,564 Views
Last Modified: 2012-05-11
I have a table where the index is identity type , thus autoincrement
in vaccess i was used to do a get last record first, then raised this index with 1 , then do a insert with new calculated value
max rexord +1,    in SQL I do not know how a SQL call should look like to get this done
either in VB6 or the pervasive utils    type 2000i  or V10 and V11
0
Comment
Question by:BIAPRO
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:Roman Gherman
ID: 35136304
Hi,

You can not perform an insert for a identity column in MS SQL, unless you use:

SET IDENTITY INSERT table ON
-- DO INSERT HERE
SET IDENTITY INSERT table OFF

However, why do you need to do that? MS SQL will auto increment that value, just do not include that identity column name in the insert statement.

--------------
You can contact me on: http://extremedev.blogspot.com/
0
 

Author Comment

by:BIAPRO
ID: 35136370
is this also true for Pervasive ?
0
 
LVL 9

Expert Comment

by:Roman Gherman
ID: 35136410
Hi,
For Pervasive you need to put 0 for identity column:
--------------------
The following example shows what occurs when you use INSERT for IDENTITY columns and columns with default values.
CREATE TABLE t (id IDENTITY, c1 INTEGER DEFAULT 100)
INSERT INTO t (id) VALUES (0)
INSERT INTO t VALUES (0,1)
INSERT INTO t VALUES (10,10)
INSERT INTO t VALUES (0,2)
INSERT INTO t (c1) VALUES (3)
SELECT * FROM t
The SELECT shows the table contains the following rows:
1, 100
2, 1
10, 10
11, 2
12, 3
The first row illustrates that if “0” is specified in the VALUES clause for an IDENTITY column, then the value inserted is “1” if the table is empty.
The first row also illustrates that if no value is specified in the VALUES clause for a column with a default value, then the specified default value is inserted.
The second row illustrates that if “0” is specified in the VALUES clause for an IDENTITY column, then the value inserted is one greater than the largest value in the IDENTITY column.
More details on this site:
--------------------

You can find me on: http://extremedev.blogspot.com/
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:BIAPRO
ID: 35136479
ok this is my record tabel
 WEBSHOP(BasketRecord,CustIDyymmdd,OrderNumber,StatusFlag,Customer,ItemNumber,Deliverydate,QTY)  "
These are the  FIELDS        identy key     ,  string              ,string              ,string        , string,        string,           string,          float

this i call
 INSERT INTO WEBSHOP VALUES(0, 'JACK        110316 ', '         ', '0' ,JACK        ', '05.0425       ', '110316',  0)

and give error    -2147217900


0
 
LVL 9

Accepted Solution

by:
Roman Gherman earned 500 total points
ID: 35136573
An apostrophe is missing before JACK'.
Try this

INSERT INTO WEBSHOP VALUES(0, 'JACK 110316', '', '0' ,'JACK', '05.0425', '110316',  0)
0
 

Author Comment

by:BIAPRO
ID: 35136641
great !!   working perfect!  thanks a lot!
Regards Jack
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now