473,412 Members | 4,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

How do I use a variable to modify this sproc?

My first post (beginner).. I hope it is clear enough and appreciate your taking the time to consider helping.

I have an existing sproc that takes a cart transaction from a table and inserts shared values of that transaction into another table called Transaction_PT. The sproc works fine, it takes the total sale value and attributes profit share of that value to participating members. Now I need to modify this sproc to also look up the retailer's "price version". "price version" is figured out by finding the retailer's version number (between 0 and 3) and then looking at the product's table, finding the matching product_id and the matching price version. The sproc 'knows' the retailer's ID (salon_id) and the product ID. I want to know how to add code to this sproc to find the appropriate price version money amount and insert it into Transactions_PT. I am new to SQL and have never used variables before so here is the sproc followed by my rough attempt at the code to add:

ALTER PROC sp_Tran_PT_Insert
AS

INSERT INTO Transaction_PT (transaction_id_fk , pass_through_amt , salon_id , st_id,
salon_pt_pct , SSR_id , SSR_pt_pct , SP_id,
SP_pt_pct , S_Mgr_id , S_Mgr_pt_pct , st_pt_pct,
RS_Mgr_ID , rs_mgr_pt_pct)
select tr.transaction_id , tr.pass_through_amt, tr.salon_id , tr.stylist_ID,
sal.pt_pct_to_salon, ch.ssr_id , ssr.pt_pct_to_ssr , ch.sp_id,
sp.pt_pct_to_sp , ch.s_mgr_id , sm.pt_pct_to_s_mgr , sty.pt_pct_to_stylist,
rsm.rs_mgr_id , rsm.pt_pct_to_rs_mgr
from transactions tr
join Salon sal
on sal.salon_id = tr.salon_id
join channels ch
on ch.salon_id = tr.salon_id
left join sub_sales_referral ssr
on ch.ssr_id = ssr.ssr_id
left join sales_person sp
on ch.sp_id = sp.sp_id
left join sales_mgr sm
on ch.s_mgr_id = sm.s_mgr_id
left join reg_sales_mgr rsm
on ch.rs_mgr_id = rsm.rs_mgr_id
left join stylist sty
on tr.stylist_id = sty.stylist_id
where tr.processed_flag = 0
--and check TS

--NEED to update processed flag
UPDATE Transactions
SET processed_flag = 1
WHERE transaction_id in (select transaction_id_fk from transaction_pt
where calc_flag = 0)

exec sp_Tran_PT_Update

----------------------------------------------------------------------------------

declare @Version as varchar, @Price as money
set @Version = (Price_Version from Salon Where Salon_ID = Salon_ID)
if @Version = 1
Set @Price = (select Version_1 from Zen_Products_Description Where Product_ID = Product_ID)
ELSE
if @Version = 2
Set @Price = (select Version_2 from Zen_Products_Description Where Product_ID = Product_ID)
ELSE
if @Version = 3
Set @Price = (select Version_3 from Zen_Products_Description Where Product_ID = Product_ID)

INSERT INTO Transaction_PT ...


Does this describe my problem well enough? Would anyone be willing to show me how to insert the price version into Transaction_PT using this sproc and a better version of my attempted code? Thanks much.

--Mat
Feb 13 '07 #1
0 1159

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

Similar topics

4
by: Greg | last post by:
I need to send the result of a procedure to an update statement. Basically updating the column of one table with the result of a query in a stored procedure. It only returns one value, if it didnt...
3
by: Edward | last post by:
ASP.NET / VB.NET SQL Server 7.0 Our client has insisted that we change our established practice of building SQL in-line and move it all to SPROCs. Not a problem for 80% of the app. However,...
1
by: teddysnips | last post by:
SQL Server 2000 I have a stored procedure that uses an extended SPROC to send an email notification to my customers when a document is distributed. However, the SPROC has an unexpected side...
3
by: Radu | last post by:
Hi. I have lots of processing to do on the server - from the client (Access) I call a sproc which returns a recordset (the sproc is essentially a big "select"). With the obtained data , I need to...
1
by: IC | last post by:
Hello, When debugging a SQL sproc in VS.NET, is there a way to get the debugger to retrieve the full value of a SQL variable if its content is longer than 256 characters? I currently have a...
5
by: Jiggaz | last post by:
Hi, Look my stored procedure : __________________ ALTER PROCEDURE dbo.CreateAccount @Nickname varchar(30), @Password varchar(15), @Email varchar(50), @Date datetime,
7
by: Mike L. | last post by:
Hi, I got this 'EXECUTE permission denied on object <mySproc>' error message everytime I try executing my SQL server Sproc. What's this and how to fix this err? many thnaks in advance, mike
5
by: =?Utf-8?B?UlBhcmtlcg==?= | last post by:
I used the wizard to generate a typed dataset for my table and let it create my SPROCs. It created everything, and the GetData() method and the custom GetByUserName query works great, but when I...
1
by: Looch | last post by:
Hi All, I originally wrote a sproc with one of the parameters set as SqlDBType.nvarchar,8. The parameter in the sproc was defined as 8 cahracters and the column in the table was also set to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.