sql server - SQL Stored Procedure Combine UNION rows into 1 row -


i love know how put results of query 1 row instead of 3 rows gives back:

select count([fms].[dbo].[booking].bookingnumber) [fms].[dbo].[booking] inner join [fms].[dbo].[container] on [fms].[dbo].[booking].[bookingnumber] = [fms].[dbo].[container].[bookingnumber] inner join [fms].[dbo].[file] on [fms].[dbo].[container].filenumber = [fms].[dbo].[file].filenumber [fms].[dbo].[booking].relationcode = 'ship02' , [fms].[dbo].[file].eta between '2000-10-27' , '2016-10-28'  union  select count([fmsair].[dbo].[booking].bookingnumber) [fmsair].[dbo].[booking] inner join [fmsair].[dbo].[container] on [fmsair].[dbo].[booking].[bookingnumber] = [fmsair].[dbo].[container].[bookingnumber] inner join [fmsair].[dbo].[file] on [fmsair].[dbo].[container].filenumber = [fmsair].[dbo].[file].filenumber [fmsair].[dbo].[booking].relationcode = 'ship02' , [fmsair].[dbo].[file].eta between '2000-10-27' , '2016-10-28'  union  select count([fmsprojects].[dbo].[booking].bookingnumber) [fmsprojects].[dbo].[booking] inner join [fmsprojects].[dbo].[container] on [fmsprojects].[dbo].[booking].[bookingnumber] = [fmsprojects].[dbo].[container].[bookingnumber] inner join [fmsprojects].[dbo].[file] on [fmsprojects].[dbo].[container].filenumber = [fmsprojects].[dbo].[file].filenumber [fmsprojects].[dbo].[booking].relationcode = 'ship02' , [fmsprojects].[dbo].[file].eta between '2000-10-27' , '2016-10-28' 

is there way can combine 3 result rows , count them 1 row. using inside stored procedure.

if want sum count of 3 select queries, this:

select sum(cnt) from(    select count([fms].[dbo].[booking].bookingnumber) cnt    [fms].[dbo].[booking]    inner join [fms].[dbo].[container] on [fms].[dbo].[booking].[bookingnumber] = [fms].[dbo].[container].[bookingnumber]    inner join [fms].[dbo].[file] on [fms].[dbo].[container].filenumber = [fms].[dbo].[file].filenumber    [fms].[dbo].[booking].relationcode = 'ship02' , [fms].[dbo].[file].eta between '2000-10-27' , '2016-10-28'    union    select count([fmsair].[dbo].[booking].bookingnumber)     [fmsair].[dbo].[booking]    inner join [fmsair].[dbo].[container] on [fmsair].[dbo].[booking].[bookingnumber] = [fmsair].[dbo].[container].[bookingnumber]    inner join [fmsair].[dbo].[file] on [fmsair].[dbo].[container].filenumber = [fmsair].[dbo].[file].filenumber    [fmsair].[dbo].[booking].relationcode = 'ship02' , [fmsair].[dbo].[file].eta between '2000-10-27' , '2016-10-28'    union    select count([fmsprojects].[dbo].[booking].bookingnumber)     [fmsprojects].[dbo].[booking]    inner join [fmsprojects].[dbo].[container] on [fmsprojects].[dbo].[booking].[bookingnumber] = [fmsprojects].[dbo].[container].[bookingnumber]    inner join [fmsprojects].[dbo].[file] on [fmsprojects].[dbo].[container].filenumber = [fmsprojects].[dbo].[file].filenumber    [fmsprojects].[dbo].[booking].relationcode = 'ship02' , [fmsprojects].[dbo].[file].eta between '2000-10-27' , '2016-10-28' ) tmp; 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -