| Author |
Topic |
|
drenard
Starting Member
7 Posts |
Posted - 2007-04-12 : 17:17:19
|
| G'Day,Can anyone show me an example of how to do the following.I have 3 table "Customer", "Employee" & "Request"I am having my users fill out the customer recordsfirst with all the correct information needed, Name,address, phone, etc. The employee table has 3 fieldsand all the records have been populated with employeeinformation, Email, Name, Ext.My goal is to have the user fill in 4 fields in the requesttable, Customer, email, salesnum, amount and upon hittin thesave button not only create the new record in the request tablebut match up the customer table and employee table and writeinto the new record that information as well. This wayall the related information will be saved as 1 new recordin the request table.I would really be thankful for any help or pointers on this..Thanx. |
|
|
drenard
Starting Member
7 Posts |
Posted - 2007-04-12 : 17:57:05
|
| Is the following even close to the ballpark ?-set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[pMyApp1Silly1Add] @p_sono varchar(50), @p_email varchar(50), @p_status varchar(50), @p_linkid nchar(10), @p_test uniqueidentifier, @p_grid_out int outputASBEGIN INSERT INTO [dbo].[silly1] ( [sono], [email], [status], [linkid], [test] ) VALUES ( @p_sono, @p_email, @p_status, @p_linkid, @p_test )Select * from silly2where silly1.customer = silly2.customerunionselect * from silly2where silly1.email = silly3.emailunion SET @p_grid_out = SCOPE_IDENTITY()END |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2007-04-12 : 22:08:23
|
| Let's start from scratch.3 tables; I put together a small script to hopfully assist. It didn't seem like you were using the right appoach. Let me know if you need further clarification.[code]create table tbl_Customer( CustomerID int not null identity(1,1), CustName varchar(50) , Address varchar(50), City varchar(50), state varchar(25), ZIP varchar(12), Phone varchar(20))create table tbl_Employee( EmployeeID int not null identity(1,1), EmployeeInfo varchar(100) , EmpName varchar(50), Ext varchar(20))create table tbl_Request( RequestID int not null identity(1,1), CustomerID int, Email varchar(60) , SalesNo varchar(50), EmployeeID int)declare @CustID int, @Email varchar(60),@SalesNo varchar(50),@EmployeeID Intset @Email = 'test@test.com'set @SalesNo = '123456' --Insert data into a table--This is just to show you the relation of data, you customer and Employee--Info will already be in the table when using in a live applicationinsert tbl_Customer(CustName,Address,City,state,ZIP,Phone)values('customer 1234','34343 no where st.', 'Bev hills','CA','90210','555-555-5555')set @CustID = Scope_Identity()insert into TBL_Employee(EmployeeInfo,EmpName,Ext)values('test info','John Doe','12345')set @EmployeeID = Scope_Identity()Insert into Tbl_Request(CustomerID,Email,SalesNo,EmployeeID)values (@CustID,@Email,@SalesNo,@EmployeeID)--Retrieve data and relation, substitute the actual colum names for * to be selectiveSelect a.*,b.*,c.* from Tbl_Request a inner join TBl_Employee bon a.EmployeeID = b.EmployeeIDinner join TBL_Customer c on a.CustomerID = c.CustomerID[/Code] |
 |
|
|
drenard
Starting Member
7 Posts |
Posted - 2007-04-12 : 23:35:41
|
| Thank you,I understand the structure..Thanks very much.. |
 |
|
|
|
|
|