Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
update sc_bill_details set dt_open_date =(select dt_bill_date from sc_bill where dt_bill_date>'2015-7-1' and sc_bill.st_bill_no=sc_bill_details.st_bill_no )


when m writing above query getting following error even after there is no null values in both the tables.

ERROR:  null value in column "dt_open_date" violates not-null constraint
DETAIL:  Failing row contains (VC2009030000242, VC20090300189, null, -1, -1, ECG, 1, 100, 100, 0, 9, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0).
Posted
Updated 14-Sep-15 21:04pm
v2
Comments
Michael_Davies 15-Sep-15 2:31am    
You say there "is no null values in both tables", have you executed the SELECT on its own outside of the UPDATE and looked at the results.
Member 11919722 15-Sep-15 2:41am    
yes Michael i did all possible research actually when inner query is running then its giving null value to date column to outer query i dont know why as per my concern my above query is correct but y inner query is returning null value
Michael_Davies 16-Sep-15 2:29am    
So, obviously there is something in the data that is amiss. We can not see the data.

Can you pull one row from the tables that produces a null and show them so we can see the source data.
Member 11919722 21-Sep-15 4:36am    
actually the problem in above query written by me is that inner query is returning null value for date columns to outer query that's why null value constraint error is coming but I don't understand how can it be possible since bith the tables have data in date columns.

1 solution

Obviously the
SQL
select dt_bill_date from sc_bill where dt_bill_date>'2015-7-1' and sc_bill.st_bill_no=sc_bill_details.st_bill_no

query does not return any value.

I have searched for PostGRE datetime specification formats; have you tried to put two digits to the month and day numbers? I did not see anything about that, but all examples I can find use '2015-07-01' as date specification format rather than '2015-7-1'. I don't know the internals of PostGRE, nor did I ever develop anyhting based on this RDBMS, but it could be worth trying.

You could also change the comparison operator to >= and see if that returns some records.

You could also try with
SQL
select dt_bill_date
from sc_bill
inner join sc_bill_details on sc_bill.st_bill_no=sc_bill_details.st_bill_no
where dt_bill_date>'2015-07-01'


Hope this helps. Good luck.
 
Share this answer
 
Comments
Member 11919722 15-Sep-15 3:42am    
thanks for your response but ur query also doesnt work with update statement since my requirement is to get dta that from july 1st to till now from sc_bill table to sc_bill_details table
Member 11919722 15-Sep-15 3:43am    
update sc_bill_details set dt_open_date =(select dt_bill_date from sc_bill where sc_bill.st_bill_no=sc_bill_details.st_bill_no)where to_char(dt_open_date,'yyyy-mm-dd')in(select to_char(dt_bill_date,'yyyy-mm-dd') from sc_bill where dt_bill_date>'2015-07-01') m trying this way thought not coming where as if we write select statemnet seperately its giving required output but not with update statement??
Member 11919722 22-Sep-15 3:09am    
Can anyone please help me with finding out solution for above query

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