Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GETAUTOINCVALUE for sqlserver
Message
 
 
To
07/12/2009 12:05:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01437880
Message ID:
01437921
Views:
53
You can insert multiple records in one INSERT command probably in all versions of SQL Server, but you can use OUTPUT clause starting from SQL Server 2005 and up.


UPDATE. I see your point - you meant multiple values in one command - this is only SQL Server 2008 feature, you're right.

>>Is there any equivalent function (GETAUTOINCVALUE) to get the autoinc value in MS SQL SERVER ?
>
>Hi Yiorgos,
>How are you doing. I would prefer "OUTPUT" clause because in SQL2008 you can insert multiple rows in one go but functions like scope_identity() return a single scalar value. Here is a sample:
>
>
>lnHandle = Sqlstringconnect("Driver={SQL Server Native Client 10.0};Server=.\sql2008;Trusted_Connection=yes;Database=test")
>TEXT TO lcSQL noshow
>CREATE TABLE MyIdTest (
>  id INTEGER IDENTITY PRIMARY KEY,
>  dummy VARCHAR(100))
>ENDTEXT
>
>SQLExec(m.lnHandle, m.lcSQL)
>
>TEXT TO lcInsertMulti noshow
>DECLARE @MyTable table( id INTEGER, myvalue varchar(10) );
>
>INSERT MyIdTest (dummy)
> OUTPUT INSERTED.id, INSERTED.dummy INTO @myTable
> VALUES ('AA'),('BB'),('CC')
>
>SELECT * FROM @myTable
>ENDTEXT
>
>SQLExec(m.lnHandle, m.lcInsertMulti, 'result')
>SQLDisconnect(m.lnHandle)
>Select result
>Browse
Cetin
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform