本文介绍了我如何用Max(Date)更新表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的选择查询: -



my select query :-

SELECT   s1.Car_id ',
         s1.Job_Card ',
		 s1.Value_Oil ',
		 s1.Change_date ',
		 s1.Current_Dist ',
		 s1.Prev_Dist ,
	         Drivers.Driver_Name '',
		 Oil_Type.Oil_Type as ',
                 s1.QTY ',
                 s1.Filter ',
                 s1.Notes '
FROM     Change_Oil s1
inner join (select Car_id, MAX(Change_date) as 'Max date '
		    from Change_Oil
		    group by Car_id ) s2
	    	on s1.Car_id = s2.Car_id
		    and s1.Change_date = s2.[Max date]
INNER JOIN dbo.Oil_Type
		ON s1.Oil_id = dbo.Oil_Type.Oil_id
INNER JOIN dbo.Drivers
		ON s1.Driver_ID = dbo.Drivers.Driver_ID
		where s1.Car_id = s2.Car_id







这是我的更新查询: -






this is my update Query :-

create proc UPDATE_CHANGE_OIL
@car_id int,
@job_card varchar(8),
@value_oil numeric(18, 2),
@change_date date,
@current_dist numeric(18, 2),
@prev_dist numeric(18, 2),
@drive_id int,
@oil_id int,
@qty numeric(18, 2),
@filter bit,
@notes text
as
update Change_Oil
   set Car_id = @car_id,
       Job_Card = @job_card,
	   Value_Oil = @job_card,
	   Change_date = @change_date,
	   Current_Dist = @current_dist,
	   Prev_Dist = @current_dist,
	   Oil_id = @oil_id,
	   QTY = @qty,
	   Filter = @filter,
	   Notes = @notes
	   where Car_id = @car_id





当我更新行时在数据网格视图中确定我想知道我在更新查询中的错误



when i update the row Determined in data grid view please i want where my mistake in Update Query

推荐答案

inner join (select Car_id, MAX(Change_date) as 'Max date '





最后有一个额外的空间。当你在下面使用它时,它可能无法工作因为你正在使用





has an extra space at the end. When you go to use it down below, it may not work cause you're using

and s1.Change_date = s2.[Max date]





而不是





instead of

and s1.Change_date = s2.[Max date ]





祝你好运。如果您需要更多帮助,请优化您的问题。



Good luck. Refine your question if you want more help.


这篇关于我如何用Max(Date)更新表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:41
查看更多