score:0
as subqueries
select
(SELECT ISNULL(SUM(Stocking_Count),0)
FROM Fish_Stocking
where fish_id = 'B2017-1' and tank_id = 'H A01' and
Date_Assigned = '2017-02-02' and stocking_date <= '2017-03-28') [Field1],
( SELECT ISNULL(SUM(NO_FISH_SWUM_OFF),0)
FROM Swim_Thru
where Dest_fish_id = 'B2017-1' and Dest_tank_id = 'H A01' and
Dest_Date_Assigned = '2017-02-02' and date_swim_thru <= '2017-03-28') [Field2]
score:0
I hope this is what you are trying which can be accomplished with UNION ALL
as below.
NOTE: I have also changed ISNULL(SUM(Stocking_Count),0)
to SUM(ISNULL(Stocking_Count, 0))
.
SELECT SUM(Total) AS Total FROM (
(SELECT SUM(ISNULL(Stocking_Count, 0)) as Total
FROM Fish_Stocking
where fish_id = 'B2017-1' and tank_id = 'H A01' and
Date_Assigned = '2017-02-02' and stocking_date <= '2017-03-28')
UNION ALL
(SELECT SUM(ISNULL(NO_FISH_SWUM_OFF, 0)) as Total
FROM Swim_Thru
where Dest_fish_id = 'B2017-1' and Dest_tank_id = 'H A01' and
Dest_Date_Assigned = '2017-02-02' and date_swim_thru <= '2017-03-28')
) Net
More questions
- Returning a single sum from 2 SQL queries
- Performance-related: How does SQL Server process concurrent queries from multiple connections from a single .NET desktop application?
- SQL Server sum from multiple tables in a single query
- How do I write a SQL Server function to return a single value from result of several queries
- How to save a single result set to a temp table from a SQL stored procedure returning multiple sets?
- Returning a SUM from DISTINCT columns in Microsoft SQL
- Returning single row vaues from SQL Server stored procedure with LINQ-to-SQL
- SQL Server 2008 - Combine SUM queries from different tables into 1 result set
- How to sum of count from 2 queries in SQL
- SQL Server: Get sum based on Id from single column
- SQL SUM of Totals from different tables in single query
- How to concatenate text from multiple rows into a single text string in SQL Server
- How to create a SQL Server function to "join" multiple rows from a subquery into a single delimited field?
- Backup a single table with its data from a database in sql server 2008
- Percentage from Total SUM after GROUP BY SQL Server
- Executing SQL Server Agent Job from a stored procedure and returning job result
- Append Results from two queries and output as a single table
- How do I restore a single table from a SQL Server 2005 backup?
- What happens with returning IEnumerable if used with async/await (streaming data from SQL Server with Dapper)?
- Multiple Row Update SQL Trigger from Single Update SQL Statement
- How to sum multiple SQL queries together?
- SQL - Take data from multiple rows into single row
- Get a single record from SQL Server the correct way
- SQL Group By - Generate multiple aggregate columns from single column
- What is the fastest way to delete all customers from SQL Server based on that customer not meeting a single criteria
- Sum results from two different queries (SQL)
- Queries that include a column with large NVARCHAR values from from SQL Azure are slow
- NHibernate - returning complex object from sql function
- How to multiply a single row with a number from column in sql
- How can inefficient SQL queries be prevented from slowing a database server
More questions with similar tag
- T-SQL | Counts and ranks
- Linq to SQL: SELECT latest DISTINCT entries
- SQL Server 2005 GROUP BY and COUNT query for each month
- Insert manually into a table by SQL statement, but key is autoincremented
- How to use XML AUTO with SQL to create a structure with 2 nested tables
- SqlCredential and SecureString lifetime management
- How would a SQL Server 2005 database lose a few days data?
- TSQL Pivot with strings
- Query performance of non clustered index during inner join
- Why is there a "no such file or directory" error when the .so file does exist?
- How can I test for SQL Server connectivity from DOS?
- How to deny write premissions to a user for all tables except one
- Converting text to binary code - TSQL
- SELECT/UPDATE Deadlock on the Primary Key
- How can I resolve this error an c#
- Check if value of ColumnA is in ColumnB if parameter is not null (SQL-Server)
- Using IN with multiple linked conditions - SQL
- Selecting 7th Person (row) and get 7 as result
- SQL Server Analysis Services and Team Foundation Server
- Import text file into SQL Server table using SqlBulkCopy in C# (How to use it?)
- How to turn off ANSI_WARNINGS using PDO in PHP
- Re-create an existing sql server database programatically?
- Get SQL Server Instances in Windows 10
- Change SQL Server encryption algorithm
- Parameterize insert of multiple rows
- PHP PDO Login fails when inactive for long periods
- Automatically print SSRS report?
- Need help making my stored procedure more efficient
- combine one to more tables and get the values
- NHibernate - does it work well with database-level cascading deletions on foreign key constraints
Source:
stackoverflow.com