Click here to Skip to main content
15,909,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Table Name:- IndividualSalaryParameters

ISPID SPID EMPNO  AMOUNT 	SUBMISSIONDATE 	MONTHNO TYPE
11		8	1		 	 2000			2013-02-01 00:00:00.000	2/2013		0
12		8	2	         	 300	  		2013-06-01 00:00:00.000	5/2013		0
13		8	1	      		 1500			2013-06-19 00:00:00.000	6/2013		0
14		8	1		 	 2500			2013-05-19 00:00:00.000	6/2013		0

Here amount us dedection amount. Please checkout stored procedure.

I have problem in my query
SQL
if exists(select EmployeeNo from IndividualSalaryParameters where EmployeeNo=@EmpID and SPID=8)
begin
	set @MaxDeductSalary_Date=(select max(SubmissionDate) from IndividualSalaryParameters where SubmissionDate<=@Date and EmployeeNo=@EmpID and SPID=8)
	SELECT @MaxDeductSalary_Date
set @DeductSalary=(select amount from IndividualSalaryParameters where SubmissionDate<=@MaxDeductSalary_Date and EmployeeNo=@EmpID and SPID=8)
print @DeductSalary
end


In my query return More than one row ........
I want to Output data According to SubmissionDate i e -submission date=2013-02-01 then fetch only amount=2000,
submissiondate=2013-06-19 then fetch only amount=1500 and so on means only one record at selected submission date

how can alter in my query Please suggest Sir
Posted
Updated 12-Sep-13 21:26pm
v2

It should be something like this:
SQL
SELECT TOP(1) *
FROM IndividualSalaryParameters
WHERE SubmissionDate=@subdate AND Amount=@amount
ORDER BY ISPID DESC
 
Share this answer
 
Comments
Faizymca 13-Sep-13 7:24am    
Thanx for reply ..Maciej los sir, actually here when i execute this type table only return the top row data like 2000
i need according to return data condition of SubmissionDate and EmpNo column exact match of related Amount Column...
I guess this is the problem.

Change the condition SubmissionDate<=@MaxDeductSalary_Date to SubmissionDate=@MaxDeductSalary_Date
 
Share this answer
 
Comments
Faizymca 13-Sep-13 7:26am    
Thanx for reply ..Maciej los sir, actually here when i execute this type table only return the first row SubmissionDate and return data column every time like 2000
i need according to return data condition of SubmissionDate and EmpNo column exact match of related Amount Column...
ArunRajendra 13-Sep-13 9:01am    
You have replied to wrong answer.
Faizymca 14-Sep-13 7:39am    
Sorry Arun Sir this answare related to query of Maciej sir....
Faizymca 17-Sep-13 6:19am    
set @DeductSalary=(select amount from IndividualSalaryParameters where SubmissionDate<=@MaxDeductSalary_Date and EmployeeNo=@EmpID and SPID=8)

Arun SIr whenever i execute this query if amount 1200 for month of 01-jan-2013 then it's ok if i go for next month like amount 1500 of 01-feb-2013 and then some msg are show "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 0 0 " pls find where i am wronge ??
ArunRajendra 18-Sep-13 1:26am    
post your query and sample data.

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