How do you add results of two select statements in SQL?

How do you add results of two select statements in SQL?

To combine two or more SELECT statements to form a single result table, use the set operators: UNION, EXCEPT or INTERSECT….To eliminate redundant duplicate rows when combining result tables, specify one of the following keywords:

  1. UNION or UNION DISTINCT.
  2. EXCEPT or EXCEPT DISTINCT.
  3. INTERSECT or INTERSECT DISTINCT.

Which data type can store websites or email addresses?

VARCHAR
VARCHAR is the best data type to be used for email addresses as Emails vary a lot by length.

Can you send email with results of multiple select statements?

Your first query would execute without any issue but your second query is creating a result set bigger than your settings allow so it will not send, I agree with @kin that you would be better off saving the results down somewhere and then email a link. As a bonus your network administrators will be happier too!

How to execute SQL statement and send result to email?

So, you need to pass the query definition into msdb.dbo.sp_send_dbmail like this: DECLARE @msg VARCHAR (250); DECLARE @query varchar (2048); SET @msg = ‘Please refer to the attached spread sheet for the report.’;

How to send SQL job with results of multiple select statements?

As a bonus your network administrators will be happier too! Terminate your T-SQL statements appropriately in your @query parameter with a semicolon and you’ll get both result sets in your attachment (assuming that the result sets are smaller than your attachment limit size).

How to run email query in SQL Server?

@profile_name is the Database Mail profile you want to use to send the email. You must have at least one profile already set up. @recipients is the list of email addresses to send the email to. If you have more than one, separate them with a semi-colon. @subject is the email subject. @query is the query you wish to run.