SQL Error – The specified ‘@notify_email_operator_name’ is invalid (valid values are returned by sp_help_operator)
Today while creating some SQL Jobs I faced following error:
Msg 14234, Level 16, State 1, Procedure sp_verify_job, Line 245
The specified ‘@notify_email_operator_name’ is invalid (valid values are returned by sp_help_operator).
The Job’s Script was created from PROD environment and as the same operator was not available on my DEV server, executing same script on DEV environment was throwing this error. So now how to fix this error?
–> One method is to check if an Operator already exist n DEV server and use it in your SQL Job Script:
USE [msdb] GO EXEC sp_help_operator GO
–> If the Operator does not exist then create a new Operator by using following DDL query:
USE [msdb] GO EXEC msdb.dbo.sp_add_operator @name = N'OperatorName', @enabled = 1, @email_address = N'SupportEmail@DomainName.com', @category_name = N'Uncategorized' GO
… and use the Operator name in the Script that you got from PROD server, and update the below part of the DDL Script:
DECLARE @jobId BINARY(16) EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Acquire_Data_Source1', @enabled=1, @notify_level_eventlog=0, @notify_level_email=2, @notify_level_netsend=0, @notify_level_page=0, @delete_level=0, @description=N'No description available.', @category_name=N'ESBIAcquisition', @owner_login_name=N'DOMAIN\Account', @notify_email_operator_name='Operatorname', -- <-- Here @job_id=@jobId OUTPUT
–> If you are not sure about the Operator name and just testing the Jobs in DEV or Test environment and don’t any email alerts then just assign NULL instead of the operator name like:
@notify_email_operator_name=NULL
How to convert ‘20140620’ date to ‘DD-MM-YYYY’ format – MSDN TSQL forum
–> Question:
I have data for date fields like “20140620”(YYYYMMDD) while inserting into the table it should be in the format “DD-MM-YYYY”
Can any one please help me to achive this.
–> My Response:
SELECT FORMAT(CAST('20140620' as DATE), 'dd-MM-yyyy', 'en-US'), CAST('20140620' as DATE)
… this will work with SQL Server 2012 and above.
–> Other Responses:
-- by Olaf Helper SELECT CONVERT(varchar(10), CONVERT(datetime, '20140620', 112), 105) AS DDMMYYY -- by Latheesh NK SELECT CONVERT(VARCHAR(10), '20140620', 105)
Ref Link.
Identify potential free space in Database files before shrinking – TSQL Query
Today someone in office asked me:
"How can I know how much free space might be left in a Database to Shrink before actually Shrinking it?"
–> I told it is simple, go to SSMS, select Database -> Right click -> select Task -> select Shrink -> select either Database/File.
–> It will show you Available Free Space, of the whole Database or each mdf/ldf/ndf file(s).
–> He said he already knows it, his real ask was:
"what if you've hundreds of Databases and want to know the stats for each of them? Is there any SQL Query which can give you this stats, so that you can run it against each or all Database?"
I opened SQL Profiler, ran it against the instance and again performed all manual steps defined above to check the Free space. After the Shrink File pop-up window appeared I went back to the Profiler and stopped it, which threw me lot of typical SQL Queries generated by SQL Server DB engine. I searched and found the desired query that I was looking for. I slightly tweaked the query according to my needs and here it is:
USE [AdventureWorks2012] GO select db_name() AS [DatabaseName], s.name AS [DB_File_Name], s.physical_name AS [FileName], s.size * CONVERT(float,8) AS [TotalSize], CAST(CASE s.type WHEN 2 THEN s.size * CONVERT(float,8) ELSE dfs.allocated_extent_page_count*convert(float,8) END AS float) AS [UsedSpace], CASE s.type WHEN 2 THEN 0 ELSE s.size * CONVERT(float,8) - dfs.allocated_extent_page_count*convert(float,8) END AS [AvailableFreeSpace] from sys.database_files AS s left outer join sys.dm_db_file_space_usage as dfs ON dfs.database_id = db_id() AND dfs.file_id = s.file_id where (s.drop_lsn IS NULL)
–> Output:
To Shrink Database Files check my earlier blog post: https://sqlwithmanoj.wordpress.com/2011/07/02/shrink-database-shrink-file/
Query to check AlwaysON Replica Latency for the LSNs (Log Sequence Numbers) by using DMVs
SELECT ag.NAME AS 'AG Name' ,ar.replica_server_name AS 'AG Replica Server' ,DB_NAME(drs.database_id) AS 'Database Name' ,CASE WHEN ars.is_local = 1 THEN N'LOCAL' ELSE 'REMOTE' END AS 'Is AG Replica Local' ,CASE WHEN ars.role_desc IS NULL THEN N'DISCONNECTED' ELSE ars.role_desc END AS 'AG Replica Role' ,ar.availability_mode_desc AS 'Sync Mode' ,drs.synchronization_state_desc AS SyncState ,agl.dns_name AS 'Listener Name' ,drs.last_hardened_lsn ,drs.last_hardened_time ,datediff(s, last_hardened_time, getdate()) / 60 AS 'Seconds Behind Primary' ,drs.last_commit_time FROM sys.availability_groups AS ag INNER JOIN sys.availability_replicas AS ar ON ag.group_id = ar.group_id INNER JOIN sys.dm_hadr_availability_replica_states AS ars ON ar.replica_id = ars.replica_id INNER JOIN sys.dm_hadr_database_replica_states drs ON ag.group_id = drs.group_id AND drs.replica_id = ars.replica_id INNER JOIN sys.availability_group_listeners AS agl ON agl.group_id = ars.group_id ORDER BY datediff(s, last_hardened_time, getdate()) DESC;
Top SQL Blogs – Windows 8 App | from MSDN, MVPs and Top Bloggers
Dear Readers,
After my first App [SQL with Manoj] got published on Windows 8 Store, I thought to create an another App on a broader level, which will cover latest SQL Server (TSQL) topics from MSDN blogs, MVPs and other famous Bloggers, like Paul S. Randal, Kimberly Trip, Sam Lester, Brent Ozar, etc.
And today I’m very happy to announce the release of my 2nd Windows 8 App for and its availability on Windows 8 store.
With this App you can view and read SQL Server related topics from various sources, like MSDN blogs, MVPs and other famous Bloggers at one place.
Please download this App on your Windows 8 PC or Tablet and let me know your feedback.
Thanks!!!








