Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have table Like that :- P_id, R_Number, Date_Reservation ,Exame_id , Doctor_id
P_id is FK ---- -------- ---------------- -------- ---------
50 , 1 , 20-2-2016 , 1 , 2
20 , 2 , 20-2-2016 , 1 , 1
60 , 3 , 20-2-2016 , 1 , 3
50 , 1 , 21-2-2016 , 2 , 4
30 , 2 , 21-2-2016 , 2 , 2

this is my insert query to add new P_id :-

SQL
insert into ResrvationData (P_id ,R_Number ,Date_Reservation ,Exame_id , Doctor_id)
values (1 ,(select MAX(R_Number) from ResrvationData where Date_Reservation = '2016-02-22' and Exame_id = 1 ) +1 ,'2016-02-22' ,1 ,1 )


this new P_id become :- 1 , Null , 22-2-2016 , 2 , 3

i want make R_number count using 2 values in Date_Reservation and exam_id

What I have tried:

How i solve this problem when i add a new P_id
Posted
Updated 21-Feb-16 19:53pm
Comments
CHill60 21-Feb-16 9:38am    
I can't work out what your problem is. Can you post the code you are using to "make R_number count using 2 values in Date_Reservation and exam_id" or can you find another way of explaining your problem?
Member 12244977 21-Feb-16 9:42am    
when i insert new value in P_id the R_Number Counter alone but in one condition Like where Date_Reservation = '' and exam_id = ''

1 solution

Use IsNull on this Query:

insert into ResrvationData (P_id ,R_Number ,Date_Reservation ,Exame_id , Doctor_id)
values (1 ,(select IsNull(MAX(R_Number),0) from ResrvationData where Date_Reservation = '2016-02-22' and Exame_id = 1 ) +1 ,'2016-02-22' ,1 ,1 )


Ashish Nigam
 
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