如何根据日期一次获取列数据 [英] How can Column data fetch at a time once according to date

查看:71
本文介绍了如何根据日期一次获取列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表名: - IndividualSalaryParameters



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

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





在我的查询中返回多行........

我想输出数据根据SubmissionDate即-submission date = 2013-02 -01然后只获取金额= 2000,

submissiondate = 2013-06-19然后只获取金额= 1500等等意味着在选定的提交日期只有一条记录



如何在我的查询中改变请建议Sir



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

推荐答案

它应该是这样的:

It should be something like this:
SELECT TOP(1) *
FROM IndividualSalaryParameters
WHERE SubmissionDate=@subdate AND Amount=@amount
ORDER BY ISPID DESC


我想这就是问题所在。



将条件SubmissionDate< = @ MaxDeductSalary_Date更改为SubmissionDate = @ MaxDeductSalary_Date
I guess this is the problem.

Change the condition SubmissionDate<=@MaxDeductSalary_Date to SubmissionDate=@MaxDeductSalary_Date


这篇关于如何根据日期一次获取列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆