Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Select expen.schemeno, sum(expen.amount) as Premonth,sch_mas.disp,sch_mas.sch_amount,
 sch_mas.san_no , CONVERT(varchar, sch_mas.sdate, 106)as schdate  from [dbo].[expen] inner join
  sch_mas on expen.schemeno=sch_mas.sch_no  where schemeno='W2/2013/11516' and exp_date<'2013-04-01' and 
  passingDate is not null group by sch_mas.disp, expen.schemeno,sch_mas.sch_amount,sch_mas.sdate,sch_mas.san_no

Select monyr, SUM(expen.amount) as expenamt,schemeno from expen  where exp_date>'2013-03-31' and exp_date<'2014-03-31' and schemeno='W2/2013/11516' group by monyr,schemeno

What I have tried:

combined two  queries in one result with different columns and conditions
Updated 5-May-18 23:32pm

1 solution

If the columns in both queries would be identical you could use UNION (Transact-SQL) | Microsoft Docs[^] . But since the result sets differ this is not possible.

However, depending on your situation you could take advantage the fact that a single SQL Server batch can actually return multiple result sets. For example if you execute multiple queries in a single batch in SSMS, you get all the results in separate grids. Many of the client programming languages are capable of consuming multiple results from a single SQL Server batch. For more information, see Using Multiple Active Result Sets (MARS) | Microsoft Docs[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900