Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Dynamic data Validation

$
0
0
Hi all,I have a Source table Tbl_Src that has 5 columns:Company_id,Salesrep_sales_date,Product_id,sales_Amt I have a process that runs and re-calculate the sales_amt and re-distribute portion of the sales to others based on same business rules and commission, etc...This process is also in SQL and has about 5 steps where I take the tbl_src data move it to a #tmp table and run each step. I tend to compare the total amount from #tmp table to tbl_src after each step to make sure the total amt per company did not change (zero variance).Like :Select Z.*,(z.src_amt-z.tmp_amt) as variance From(select company_id,sum(amt) as src_amt from tbl_src group by company_id) t1full outer join (select company_id,sum(amt) as tmp_amt from #tmp group by company_id) t2on t1.company_id=t2.company_id) TMy question is : I need to put this check step in a function or SP where I pass the Src and tmp tables as variables and call it from within the code without typing it five times after each step.any thoughts would be appreciated.Thanks

Viewing all articles
Browse latest Browse all 3145

Trending Articles