OVER PARTITION BY giving error in SQL Server 2008 -
i have following query:
select *, sum(balanceqty) on (partition item_code order [date]) (select date, item_code, sum(in_quantity) in_quantity, sum(issue_quantity) issue_quantity, (sum(in_quantity) - sum(issue_quantity)) balanceqty (select tbl_add_product.date date, tbl_add_product.item_code, tbl_add_product.in_quantity, 0 issue_quantity tbl_add_product item_code = 'pen' union select tbl_issue_product.date date, tbl_issue_product.item_code, 0 in_quantity, issue_quantity tbl_issue_product item_code = 'pen') x group item_code, date) o
it working fine in sql server 2012 causing error in sql server 2008. please suggest solution it.
if want solution can work on both try :
;with cte (select date, item_code, sum(in_quantity) in_quantity, sum(issue_quantity) issue_quantity, ( sum(in_quantity) - sum(issue_quantity) ) balanceqty (select tbl_add_product.date date, tbl_add_product.item_code, tbl_add_product.in_quantity, 0 issue_quantity tbl_add_product item_code = 'pen' union select tbl_issue_product.date date, tbl_issue_product.item_code, 0 in_quantity, issue_quantity tbl_issue_product item_code = 'pen') x group item_code,date) select *,(select sum(balanceqty) cte c2 c2.date <=c1.date) cte c1
Comments
Post a Comment