Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 stored procedure for insert
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

maddyslayer
Yak Posting Veteran

57 Posts

Posted - 04/18/2013 :  15:54:13  Show Profile  Reply with Quote
I have two tables

Product

prod_cd prod_type prod_active
p reg Y
q reg Y
r reg Y
s reg Y
t reg Y
u reg N
v reg N
w irreg Y
x reg Y


Customer

s_id (Pkey) cus_id prod_cd prod_state
1 1 p y
2 1 q y
3 1 v n
4 1 w n
5 2 s y
6 2 p n
7 2 q y
8 3 p n
9 4 q y
10 5 v n


What is the stored procedure to insert new records for a customer and that cus_id should have a record with each prod cd from the product table where prod_type = reg and prod_active = y and prod_state should be set to N?

What is the stored procedure to loop through the existing customer (cus_id) records and check if they have all the prod_cds with prod_active = N or else add the prod_cds with prod_active = N that are not there and insert those records for that cus_id with prod_state set to N?

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 04/19/2013 :  02:32:07  Show Profile  Reply with Quote
where does the customerid come from? is it user input?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

maddyslayer
Yak Posting Veteran

57 Posts

Posted - 04/22/2013 :  14:31:21  Show Profile  Reply with Quote
It is not user input, each customer has a unique id with different products
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 04/23/2013 :  13:05:16  Show Profile  Reply with Quote
so what should be output for above sample data?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000