Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Seequiller
Starting Member
3 Posts |
Posted - 2008-09-24 : 12:54:35
|
| My Save function inserts and updates a record in my project. I have an Address table (adddress_ID, street_add, city, state, zip_code, county), and a Customer table (customer_ID, address_ID, name, trade_name, phone_number).My customer table references address table to retrieve address info first. I know how to insert values into tables but need to insert, update both tables and join them together under one Save method. Any SP or Select is welcome. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-24 : 13:03:13
|
| [code]CREATE PROC InsertData@street_add varchar(100),@city varchar(100),..@name varchar(100),@trade_name varchar(100),...ASDECLARE @Address_ID intIF NOT EXISTS (SELECT 1 FROM Address WHERE street_add=@street_addAND city=@cityAND state=@stateAND zip_code=@zip_codeAND county=@county)BEGININSERT INTO Address(fields..)SELECT @street_add, @city,..SET @Address_ID = SCOPE_IDENTITY()ENDELSEBEGIN SELECT @Address_ID =Address_IDFROM Address WHERE street_add=@street_addAND city=@cityAND state=@stateAND zip_code=@zip_codeAND county=@countyENDINSERT INTO Customer(fields..)SELECT @Address_ID,...GO[/code]i've not included all columns. remeber to include them in select and insert list |
 |
|
|
Seequiller
Starting Member
3 Posts |
Posted - 2008-09-25 : 14:42:01
|
| Thank you visakhlcI got part of the select created and it is similar to your example. I had a migraine yesterday and had to leave for the day so sorry I did not reply back.Thank you for your responses, I have an idea now. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 01:57:22
|
quote: Originally posted by Seequiller Thank you visakhlcI got part of the select created and it is similar to your example. I had a migraine yesterday and had to leave for the day so sorry I did not reply back.Thank you for your responses, I have an idea now.
No worries You're always welcome |
 |
|
|
|
|
|
|
|