Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my select query :-

SQL
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 :-

SQL
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
Posted
Updated 10-Jan-16 23:01pm
v2
Comments
Herman<T>.Instance 11-Jan-16 5:01am    
'i want where my mistake in Update Query' ????
What is your problem?
phil.o 11-Jan-16 5:23am    
What are all these single quotes in your select query? They shouldn't be here.
Is it a typo on CP or in your query?
ZurdoDev 11-Jan-16 10:21am    
This is very unclear. Your title says MAX(Date) but then you don't seem to ask about MAX at all.

So, what exactly is your question?

1 solution

Not sure what your error is, but the line

SQL
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

SQL
and s1.Change_date = s2.[Max date]


instead of

SQL
and s1.Change_date = s2.[Max date ]


Good luck. Refine your question if you want more help.
 
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