sql - Aggregate function exception when I run my query -


this extension of previous question(getting exception datetime diff), time i've made totalbreaktime float , below new query.

merge time_tracker target using (select userid, cast(datediff(second,starttime,endtime)/60.0 numeric(36,2)) columnwithbreakscount breakstable  convert(date, starttime) = convert(date, getdate()) group userid) source on target.userid = source.userid  when matched update set breaks = source.columnwithbreakscount; 

this time when run query, i'm getting below exception.

msg 8120, level 16, state 1, line 1 column 'breakstable.starttime' invalid in select list because not contained in either aggregate function or group clause. msg 8120, level 16, state 1, line 1 column 'breakstable.endtime' invalid in select list because not contained in either aggregate function or group clause. 

problem:

  1. as discussed in previous question, want update time_tracker.breaks sum of breakstable.totalbreaktime based on date.
  2. when run query(the previous one), considering data instead of current date's data.

and table data below.

time_tracker

enter image description here

breakstable

enter image description here

please let me know going wrong , how can fix this.

thanks

you have subquery in query:

select userid,        cast(datediff(second, starttime, endtime)/60.0 numeric(36,2)) columnwithbreakscount breakstable  convert(date, starttime) = convert(date, getdate()) group userid; 

the second column not aggregated column, nor columns in expression in group by clause. hence error.

i can speculate want sum() second column:

merge time_tracker target using       (select userid,               cast(sum(datediff(second, starttime, endtime)) / 60.0 numeric(36,2)) columnwithbreakscount        breakstable         convert(date, starttime) = convert(date, getdate())        group userid       ) source       on target.userid = source.userid  when matched update set breaks = source.columnwithbreakscount; 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -