Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL
Hi All,
 
I have 3 tables like, 'Customer Table', 'Task Table' and 'Enquiry Table'. Here when i update the customer info, those information is saved to 'Customer Table' and generate a customerID. After that I need to insert the enquiry details of that customer (Here Enquiry and task details are Similar), so when I update the enquiry details, I am creating the row in 'Task Table' and in 'Enquiry Table' and generating the ID like TID and EID. Here my challenge is, In 'Customer Table' I have column called "Latest Enquiry" and in 'EnquiryTable' I have a column called "TID", so in these rows I need to update the id(TID from 'Task Table').
 
Thanks in Advance.
Posted 25-Nov-12 20:00pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Assuming you are using MS SQL Server, you can use SCOPE_IDENTITY()[^] to capture the auto generated ID.
 
Here is a sample
DECLARE @CustomerID INT
 
--Insert Customer data
INSERT INTO Customer(Name, Email) VALUES ('Customer 1', 'xyz@xyz.com')
 
--Store the Auto generated ID in @CustomerID 
SELECT @CustomerID = SCOPE_IDENTITY()
 
 
Now you can use the "@CustomerID" variable to insert generated customer ID in another table.
 
Hope this helps.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi Chetan,
 
If you want to update TID form task table into customer table and inquiry table then first you need to insert row into Task table and then update task id into inquiry table and finally create customer table and update the id here.
 
Please let me know if you need any more help.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 359
1 _Amy 230
2 OriginalGriff 220
3 Manfred R. Bihy 200
4 CHill60 180
0 OriginalGriff 7,495
1 Sergey Alexandrovich Kryukov 6,402
2 Maciej Los 3,849
3 Peter Leow 3,568
4 CHill60 2,702


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100