sql - Select records ignoring null values with date between some range -
i want records records must exist between particular dates. e.g. if date given between 2013-7-1 , 2013-7-17 , i've entry in purchase table dated: 2013-6-5 , entry in sale table dated 2013-7-17 particular product. should ignore these rows , select rows sale & purchase have occur in desired date range. below query not working properly. because of above defined situation divided 0 exception occurs. kindly me.
select o.name owner, c.name company, sum(sq.pquantity) - sum(sq.squantity) quantity, sum(sq.pquantity * sq.prate) / sum(sq.pquantity) rate, (sum(sq.pquantity) - sum(sq.squantity)) * (sum(sq.pquantity * sq.prate) / sum(sq.pquantity)) amount,sq.companyid companyid, o.ownerid ownerid (select ownerid, companyid, quantity pquantity, ratepershare prate, 0 squantity, 0 srate, date purchase union select ownerid, companyid, quantity pquantity, 0 prate, 0 squantity, 0 srate, date bonus union select ownerid, companyid, quantity pquantity, costofshare prate, 0 squantity, 0 srate, date rightshare union select ownerid, companyid, 0 pquantity, 0 prate, quantity squantity, ratepershare srate, date sales) sq inner join owner o on sq.ownerid = o.ownerid inner join company c on sq.companyid = c.companyid (sq.ownerid = @param1) , (convert(date, sq.date, 111) between @param2 , @param3) group sq.companyid, c.name, o.name, o.ownerid
add having sum(sq.pquantity) > 0
bottom of query.
Comments
Post a Comment