In SQL Server, you can use the sysmail_help_status_sp
stored procedure on the msdb
database to check the status of the Database Mail queues.
Tag: t-sql
Return a List of Emails Sent from SQL Server Database Mail (T-SQL)
If you use Database Mail in SQL Server, you can use the sysmail_sentitems
view to return a list of all emails that Database Mail has sent.
Check the Status of All Database Mail Messages in SQL Server (T-SQL)
If you use Database Mail in SQL Server, you can use the sysmail_allitems
view to check the status of all emails that Database Mail has processed.
Find Out Why an Email Failed to Send in SQL Server (T-SQL)
If you’re trying to send email using Database Mail in SQL Server, but it fails to send, you can check the sysmail_event_log
view to see why it failed.
The sysmail_event_log
view returns one row for each Windows or SQL Server message returned by the Database Mail system. By “message”, I don’t mean the actual mail message. I mean a message such as the error message that explains why the mail failed.
You can also use the sysmail_configure_sp
stored procedure to determine what types of messages are logged.
Check for Failed Email in SQL Server (T-SQL)
If you’re trying to send mail with SQL Server but it’s not being delivered, try checking the sysmail_faileditems
view.
Check Unsent Mail in SQL Server (T-SQL)
When sending emails from SQL Server, you can check for any unsent mail with the sysmail_unsentitems
view.
SQL Server Error 109: There are more columns in the INSERT statement than values specified in the VALUES clause
This is a commonly encountered error in SQL Server when inserting data into a table. The full error goes like this:
Msg 109, Level 15, State 1, Line 1 There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
This happens when you specify more columns in the INSERT
statement than the number of values that you’re trying to insert with the VALUES
clause.
This will occur if you accidentally omit one or more values from the VALUES
clause.
You’d get a similar (but technically different) error if you tried to do the opposite – specify fewer columns in the INSERT
statement than you try to insert.
How EXCEPT Works in SQL Server
You can use the T-SQL EXCEPT
operator in SQL Server to return distinct rows from the left input query that aren’t output by the right input query.
How INTERSECT Works in SQL Server
In SQL Server, you can use the T-SQL INTERSECT
operator to return distinct rows that are output by both the left and right input queries.
Fix “profile name is not valid” When Sending Mail from SQL Server
If you try to send mail from SQL Server, but you get a “profile name is not valid” it’s probably because you haven’t specified a valid profile for the @profile_name
argument.