Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
declare @Con1 numeric(13,2),
@Con2 numeric(13,2),
@Con3 numeric(13,2),
@Con4 numeric(13,2),
@Con5 numeric(13,2),
@Con6 numeric(13,2),
@con numeric(13,2)
if(@Con1 ='70') and( @Con1<'80')
Begin
Set @con='10'
end
else if (@Con2 ='81' and @Con2<'104')
Begin
Set @con ='15'
end
else if(@Con3 ='105' and @Con3<'114')
begin
Set @con ='25'
end
else if(@Con4 ='115' and @Con4<'129')
begin
Set @con ='30'
end
else if(@Con5 ='130' and @Con5<'150')
begin
Set @con ='40'
end
else if(@Con6 ='150' and @Con6<'170')
begin
Set @con ='50'
end



create table #employee_cash_incentive
(
inv_no varchar(20),
acc_code varchar(20),
creation_date datetime,
agent_name varchar(80),
amount numeric(13,2),
amount_out numeric(13,2),
net_amount numeric(13,2),
inv_status varchar(30),
acc_name varchar(150),
Supervisor_name varchar(140),
call_count int,
sale_count int,
organisation varchar(300),
service_amount_in numeric(13,2),
service_amount_out numeric(13,2),
product_amount_in numeric(13,2),
product_amount_out numeric(13,2),
hosting_amount_in numeric(13,2),
hosting_amount_out numeric(13,2),
target_amount numeric(13,2),
salary numeric(13,2),
RPC numeric(13,2),
Con numeric(13,2),
Final_Payment numeric(13,2),
cal numeric(13,2),
cal_rs numeric(13,2),
Released_final_amount numeric(13,2)

)

What I have tried:

How will we pass the value of @con to con column in the
Posted
Updated 13-Dec-16 10:24am

1 solution

SQL
CREATE TABLE #GetCon
(
	id INT IDENTITY(1,1) PRIMARY KEY,
	con1 INT  NULL,
	con2 INT NULL,
	value numeric(13,2) NULL
)

--You need to create a table for your variables. Why do you have multiple values con1, con2, con3, con4 etc?
--You only need to assign to two.
--You need to provide more information. Your question isn't well formed.
INSERT INTO #GetCon
(con1, con2, value)
VALUES(70,80,10),
(81, 104,15),
(105,114,25),
(115,129,30),
(120,150,40),
(150, 170, 50)

DECLARE @con1 INT,
@con2 INT,
@value numeric(13,2)

SET @con1 = 70
SET @con2 = 80

SET @value = (SELECT value FROM #GetCon
			  WHERE con1 >= @con1 and con2 <= @con2)

create table #employee_cash_incentive
(
inv_no varchar(20),
acc_code varchar(20),
creation_date datetime,
agent_name varchar(80),
amount numeric(13,2),
amount_out numeric(13,2),
net_amount numeric(13,2),
inv_status varchar(30),
acc_name varchar(150),
Supervisor_name varchar(140),
call_count int,
sale_count int,
organisation varchar(300),
service_amount_in numeric(13,2),
service_amount_out numeric(13,2),
product_amount_in numeric(13,2),
product_amount_out numeric(13,2),
hosting_amount_in numeric(13,2),
hosting_amount_out numeric(13,2),
target_amount numeric(13,2),
salary numeric(13,2),
RPC numeric(13,2),
Con numeric(13,2),
Final_Payment numeric(13,2),
cal numeric(13,2),
cal_rs numeric(13,2),
Released_final_amount numeric(13,2)

)

--Typically you insert values into your table. Otherwise, if values exist, you update your table. Is your inv_no unique? Will that be your identifier for updates?
INSERT INTO #employee_cash_incentive 
(inv_no,Supervisor_name,call_count,Con)
VALUES('1','Jim Smith',5,@value)

SELECT inv_no,Supervisor_name,call_count,Con FROM #employee_cash_incentive 

DROP TABLE #employee_cash_incentive
DROP TABLE #GetCon
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900