Solved

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

Posted on 2011-03-15
6
1,650 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

789 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