Link to home
Start Free TrialLog in
Avatar of Anthony Matovu
Anthony MatovuFlag for Uganda

asked on

Run a query from result of another query - vb.net

I have the two queries below and i would want query two to be summaries from the results of query 1, I don't option for combining the two queries because the data source is too big and therefore query would take long.

Anthony

1.   tsql = "select id as userid, total_rev_amt, usage_type_nm, dedicated_account_used_cd from fct_subs_marketing_snapd " _
                   & " where snapshot_date_key = 20150101

 2. 'select userid,  sum(total_rev_amt) as rev_tot,sum(case when usage_type_nm = 'DATA' then total_rev_amt else 0 end) as rev_dat
        from temp group by userid

 [result of the above query]
Avatar of Karrtik Iyer
Karrtik Iyer
Flag of India image

Are you looking for a SQL solution or a LINQ solution?
In terms of SQL,
1> you can first fire query 1 and store the results in a temp table or a in memory table.
insert into #mytemptable select id as userid, total_rev_amt, usage_type_nm, dedicated_account_used_cd from fct_subs_marketing_snapd where snapshot_date_key = 20150101

Open in new window

2> And in query 2 use the temp table or the in memory table generated in step 1.

you can also combine both of these statements in a stored procedure and call that stored procedure from .NET.
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial