473,803 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the Auto Generated Column values after Insertion

50 New Member
Hi Everyone ! im using SQL SERVER 2005,
My problem is, i am inserting a set of values into a table using a subquery, the problem occurs when i tried to get the auto generated column in the table which iam trying to insert.

ex:

create procedure Sample
@ID
Insert into sampleTable1(na me,name2,name3)
(Select name,name2,name 3 from sampleTable2 where SID=@SID)

Here i try to insert a set of values into the sampleTable1 By passing a parametter values(@ID), After inserting i tried to get the autoGenerated column in the sampleTable1

I tried with the Scope Identity, but i think this wil not work out in a large network,
@@Identity as IID

I need a alternative solution for this
Kindly provide me with a valid solution

Thanks in advance !
Sep 3 '07 #1
3 7451
Mam139
2 New Member
Hi Everyone ! im using SQL SERVER 2005,
My problem is, i am inserting a set of values into a table using a subquery, the problem occurs when i tried to get the auto generated column in the table which iam trying to insert.

ex:

create procedure Sample
@ID
Insert into sampleTable1(na me,name2,name3)
(Select name,name2,name 3 from sampleTable2 where SID=@SID)

Here i try to insert a set of values into the sampleTable1 By passing a parametter values(@ID), After inserting i tried to get the autoGenerated column in the sampleTable1

I tried with the Scope Identity, but i think this wil not work out in a large network,
@@Identity as IID

I need a alternative solution for this
Kindly provide me with a valid solution

Thanks in advance !




Hi,

Do You need to find the last auto generated number for your sampletab1???
If so here is the Solution.
declare one output variable in your procedure, after the insert statement get the scope_identity( ) and assign it to output variable.
ex:

create procedure Sample
@SID INT,
@OutVar Int OUTPUT
AS
Begin
Insert into sampleTable1(na me,name2,name3)
(Select name,name2,name 3 from sampleTable2 where SID=@SID)

Select @outVar = Scope_Identity( )

END

Then execute it and get the last auto generated number.

ex:
Declare @val int
Exec Sample 1, @Val OUTPUT
SELECT @VAL

Hope it works for u.

Thank u.
Sep 4 '07 #2
guriya
1 New Member
hi
i want to enter values (numbers) of fields on form (of vb6/vb.net).. and want that a table automaticaly creates in sql according to the fields those have been entered...
hows it possible ??
please help me out ....?

palkiicartooon@ yahoo.com
Sep 16 '08 #3
ck9663
2,878 Recognized Expert Specialist
Loop through your form to gather the field names, size, etc...

Then put it in a variable...Then do a dynamic query.

-- CK
Sep 16 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
5677
by: Nick | last post by:
Is it possible to have multiple auto increments in one column? Say I have two tables... 1. table 'messageboards' with fields ('id' , 'name') 2. table 'messagethreads' with fields ('id' , 'messagethread' , 'messageboard_id') The 'messagethreads.id' column could have multiple auto increments. Then I could easily query a messageboard with ("SELECT * FROM
6
5075
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
1
1911
by: Prince | last post by:
Hi all, Can anyone tell me how to create auto generated values in a DataTable column? Looking forward for the reply.... Thanx in advance...
0
1561
by: Viorel | last post by:
Working as a beginner with data objects in Visual Studio 2003 and C#, I use the "Generate Dataset" command in order to generate automatically the dataset objects based on data adapters. Generated objects offer a convenient way of working with database fields. For instance, if a database table contains a "quantity" column, then, in the program, you will use expressions like "row.quantity". This is more comfortable then writing something as...
41
3167
by: pb648174 | last post by:
In a multi-user environment, I would like to get a list of Ids generated, similar to: declare @LastId int select @LastId = Max(Id) From TableMania INSERT INTO TableMania (ColumnA, ColumnB) SELECT ColumnA, ColumnB From OtherTable Where ColumnC > 15 --get entries just added
2
3064
by: x0054 | last post by:
Ok, this is a stupid problem, I admit. I have a scrip that adds records to a table. The records are for photos. So, after adding a record the scrip also uploads a picture from users computer and renames it to {$recordID}.jpg. The problem is, my recordID field is auto incrementing in mySQL. So currently I just take the last added record and assume that it the one I just added, and rename the file to the recordID of that record. It works,...
0
1052
by: hellboss | last post by:
Hi im using asp.net vs05 with sql05 , I Started on creating a Stored Procedure where i wrote some insert statement and i just got the Auto Generated column value by using Scope identity or @@identity, But what is my Problem is iam using Bussiness Logic , Xsd file (Table adapter to get access to the Database) , Out there in the Table Adapter i Tried inserting some values , it worked but i couldnt get the Auto Generated Primary key value ? ...
2
3538
by: Zunil | last post by:
Hi All, We are testing one of our component with JDBC + DB2 using db2jcc driver. We afced a strange issue. Scenario is like this. 1. We insert 1 record to a table having IDENTITY column as the primary key and retrieve the newly inserted identity value using getGeneratedKeys() API of JDBC 3.0. It works fine 2. Immediate after that we insert a record into another table which is having no identity column. But after insert if I call...
9
1758
by: KDawg44 | last post by:
Hi, I have PHP function that adds a record to the database. The table has an ID that is AUTO_INCREMENT. Is there anyway to get that ID back when I do any kind of insert? That ID is a foreign key that I need to do an insert on afterwards. Thanks. Kevin
0
9565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.