Problems displaying this newsletter? View online.
SQL Server Central
Featured Contents
Question of the Day
Featured Script
The Voice of the DBA
 

Daily Coping Tip

Choose one of your strengths and find a way to use it

I also have a thread at SQLServerCentral dealing with coping mechanisms and resources. Feel free to participate.

For many of you out there working in a new way, I'm including a thought of the day on how to cope in this challenging time from The Action for Happiness Coping Calendar. My items will be on my blog, feel free to share yours.

Think Marathon, not Sprint

I saw an article about automating responses to security issues being a marathon not a sprint. The articles gives a few examples of different levels of automation response to situations, noting that each of this is a different level of maturity in the organization. At early stages, the response is mostly alerting a human to take action. Later, the automation will make some changes, but still defer to a human for more actions. The final example is automation handling most of the issue itself.

The idea is that improving security with automation is something that takes place across time, as the organization matures and becomes more comfortable and trusting of automation. It's a marathon, where we push, but we know this will take some time to get to the end. It's not a sprint where we make a quick fix and get a result.

Actually a lot of things are marathons in the technology area. That's if we are looking to improve how we work with automation. If we like just firefighting issues and building quick patches, then we're constantly sprinting.

A lot of the work I do in advising clients about DevOps is to get them to think marathon. There isn't really a finish line, but we are racing our competitors and trying to improve how we work. We just need to recognize that this is a process that takes months, not minutes. We want to mature and evolve processes, making them better over time. We also start small with our scope, hoping that we expand things to the entire organization over time, but again, that time is months.

This was my same approach as both a developer and DBA. Find something that I can automate to make better, start to improve it, learn from success and failure, and repeat. At some point, I usually found something was working well enough to move on to a new area to improve. If I needed to come back and continue to improve something, I could do that as well.

I don't like sprinting. In real life, or in technology. I prefer to think marathon. We are pushing to achieve something, but with the further away future in mind, not the next few minutes.

Steve Jones - SSC Editor

Join the debate, and respond to today's editorial on the forums

 
 Featured Contents
Stairway to Integration Services

A Custom Execution Method – Level 19 of the Stairway to Integration Services

Andy Leonard from SQLServerCentral.com

The next level of the Stairway to Integration Services looks at how you can execute your package.

External Article

Deep SQL Query Optimization with SQL Grease

Additional Articles from MSSQLTips.com

Learn how to conduct deep SQL Query optimization with SQL Grease with the Enterprise dashboard, historical data, troubleshooting SQL Server Wait Stats, capturing anomalies and intelligent notifications.

External Article

A Programmer’s Guide to Flyway Configuration

Additional Articles from Redgate

Phil Factor offers a programmer's guide to Flyway's configuration settings, explaining the different categories of parameters, the role of each of parameter within each category, and how to exploit Flyway's multi-level configuration file system.

Blog Post

From the SQL Server Central Blogs - Using dbachecks for CIS Security Checks

Tracy Boggiano from Database Superhero’s Blog

Well back at the end of 2019 I finished writing most of the checks related to the CIS Center for Internet Security requirements.  I have yet to write a...

Blog Post

From the SQL Server Central Blogs - Checkpoint Analysis: Your Exclusive How-To with XEvents

SQLRNNR from SQL RNNR

Checkpoints are essential in SQL Server to help with the durability and reliability of data persisted in the database. When done right, you barely even notice them and performance...

 

 Question of the Day

Today's question (by Steve Jones - SSC Editor):

 

A Virtual FROM Source

I want to get some data in a SELECT statement, but I don't have a table or view that matches my needs. What can I put into the FROM clause that will let me specify the data I need?

Think you know the answer? Click here, and find out if you are right.

 

 

 Yesterday's Question of the Day (by Steve Jones - SSC Editor)

Azure SQL Database (2022)

What deployment options are available for Azure SQL Database in Jan 2022?

Answer: Single database, elastic pool, and Hyperscale

Explanation: Azure SQL Database is the database PaaS offering from Microsoft. The deployment options are single database and elastic pool. Ref: Azure SQL Database Overview - https://docs.microsoft.com/en-us/azure/azure-sql/database/sql-database-paas-overview

Discuss this question and answer on the forums

 

Featured Script

MSSQL Server AlwaysON: Get alerted for inconsistencies in logins, jobs and databases

Arun Yadav from SQLServerCentral

This script will create the necessary login and linked servers on a given availability replica. Please ensure that the script is executed on all the replicas.

/**********************************************************************
* Name: AO_Check_create_login_and_linked_server.sql
* Created by: Arun Yadav
* Purpose: This script will create the necessary login and linked servers
* on a given availability replica. Please ensure that the script is executed on all the replicas.
* Updated By:
* Updated on:
* Comments:
* Disclaimer: Though the script has been tested however, I do not take any guarantees,
* it is advised to test the scripts again before implementing in production
**********************************************************************/

USE [master]
GO
SET NOCOUNT ON
GO

DECLARE @AO_checkusr nvarchar (20), @AO_checkPasswd nvarchar (20), @Replica_List nvarchar(100)
SET @Replica_List = (SELECT Replica_name = STUFF((SELECT ', '+ replica_server_name from [sys].[availability_replicas]
FOR XML PATH('')), 1, 2, ''))
PRINT '******** Make sure there are no spaces in the login name. ********'
PRINT '******** This script has to be executed on all the availability replicas. ********
Below is the list of configured Availability Replicas:
'+@Replica_List

/*START OF EDITABLE PART*/

SET @AO_checkusr = '' -- SET THE NAME OF THE LOGIN HERE (without space) which will be used to connect to the replicas via the linked server
SET @AO_checkPasswd = '' -- SET THE PASSWORD HERE for the login which will be used to connect to the replicas via the linked server

/*END OF EDITABLE PART*/

IF EXISTS(SELECT 1 from SYSLOGINS WHERE NAME = @AO_checkusr)
BEGIN
PRINT 'A login with name ['+@AO_checkusr+'] already exists.'
END
ELSE
BEGIN
DECLARE @LOGINQRY NVARCHAR(200)
SET @LOGINQRY = 'CREATE LOGIN ['+@AO_checkusr+'] WITH PASSWORD=N'''+@AO_checkPasswd+''', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF'
--PRINT @LOGINQRY
EXEC (@LOGINQRY)
END

DECLARE @PERMISSIONQRY NVARCHAR (2000)
--DECLARE @AO_checkusr nvarchar (20)
--SET @AO_checkusr = 'AO_check'
SET @PERMISSIONQRY = 'IF EXISTS(SELECT 1 FROM SYSUSERS WHERE NAME ='''+@AO_checkusr+''')
BEGIN
PRINT ''The user already exists in master db.''
END
ELSE
BEGIN
PRINT ''Creating user in master db.''
CREATE USER ['+@AO_checkusr+'] FOR LOGIN ['+@AO_checkusr+']
END
GRANT VIEW SERVER STATE TO ['+@AO_checkusr+']
ALTER ROLE [db_owner] ADD MEMBER ['+@AO_checkusr+']
'
--PRINT @PERMISSIONQRY
EXEC (@PERMISSIONQRY)

USE [msdb]

--DECLARE @PERMISSIONQRY NVARCHAR (2000)
--DECLARE @AO_checkusr nvarchar (20)
SET @AO_checkusr = 'AO_check'
SET @PERMISSIONQRY = 'IF EXISTS(SELECT 1 FROM SYSUSERS WHERE NAME ='''+@AO_checkusr+''')
BEGIN
PRINT ''The user already exists in msdb db.''
END
ELSE
BEGIN
PRINT ''Creating user in msdb db.''
CREATE USER ['+@AO_checkusr+'] FOR LOGIN ['+@AO_checkusr+']
END
ALTER ROLE [DatabaseMailUserRole] ADD MEMBER ['+@AO_checkusr+']
ALTER ROLE [db_datareader] ADD MEMBER ['+@AO_checkusr+']
ALTER ROLE [ServerGroupReaderRole] ADD MEMBER ['+@AO_checkusr+']
ALTER ROLE [SQLAgentOperatorRole] ADD MEMBER ['+@AO_checkusr+']
ALTER ROLE [SQLAgentReaderRole] ADD MEMBER ['+@AO_checkusr+']
ALTER ROLE [SQLAgentUserRole] ADD MEMBER ['+@AO_checkusr+']
'
--PRINT @PERMISSIONQRY
EXEC (@PERMISSIONQRY)

USE [master]

SELECT replica_server_name INTO #Temp1 FROM [sys].[availability_replicas] WHERE replica_server_name <> @@servername;

DECLARE @LINKEDSRV NVARCHAR(50)
DECLARE LINKKURSOR CURSOR FOR
SELECT * FROM #Temp1

OPEN LINKKURSOR
FETCH NEXT FROM LINKKURSOR INTO @LINKEDSRV
WHILE @@FETCH_STATUS = 0
BEGIN
print @LINKEDSRV
IF EXISTS (SELECT srvname FROM sysservers WHERE srvname = @LINKEDSRV)
BEGIN
PRINT 'Linked server with name '+ @LINKEDSRV +'already exists. Either drop the linked server and re-run this script or, jump to next script.'
--RAISERROR('Linked Server already exists', 20, -1) with log
END
ELSE
BEGIN
Print '********Creating linked server named '+ @LINKEDSRV +'********'
EXEC master.dbo.sp_addlinkedserver @server = @LINKEDSRV, @srvproduct=N'SQL Server'

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=@LINKEDSRV,@useself=N'False',@locallogin=NULL,@rmtuser=@AO_checkusr,@rmtpassword=@AO_checkPasswd

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'collation compatible', @optvalue=N'false'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'data access', @optvalue=N'true'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'dist', @optvalue=N'false'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'pub', @optvalue=N'false'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'rpc', @optvalue=N'false'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'rpc out', @optvalue=N'false'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'sub', @optvalue=N'false'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'connect timeout', @optvalue=N'0'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'collation name', @optvalue=null

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'lazy schema validation', @optvalue=N'false'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'query timeout', @optvalue=N'0'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'use remote collation', @optvalue=N'true'

EXEC master.dbo.sp_serveroption @server=@LINKEDSRV, @optname=N'remote proc transaction promotion', @optvalue=N'true'
Print '********Linked server '+ @LINKEDSRV +' created********'
END
FETCH NEXT FROM LINKKURSOR INTO @LINKEDSRV
END
CLOSE LINKKURSOR
DEALLOCATE LINKKURSOR
DROP TABLE #Temp1
GO

/**********************************************************************
* Name: Check_DBs_not_configured_in_AG.sql
* Created by: Arun Yadav
* Purpose: This script will check and e-mail if there are any databases which are present
* on a given availability replica and are missing from any other replicas.
* Updated By:
* Updated on:
* Comments:
* Disclaimer: Though the script has been tested, I do not take any guarantees,
* it is advised to test the scripts again before implementing in production
**********************************************************************/

use [master]
GO

CREATE PROCEDURE usp_Check_DBs_not_configured_in_AG
AS
BEGIN
SET NOCOUNT ON

if exists (select name from sys.databases
WHERE name Not IN ('master', 'model', 'msdb', 'tempdb','ReportServer','ReportServerTempDB')
and replica_id Is NULL)
BEGIN
DECLARE @servername sysname = (select @@servername)
DECLARE @Databases varchar (100) = (select name = STUFF((select ', ' + name from sys.databases
WHERE name Not IN ('master', 'model', 'msdb', 'tempdb','ReportServer','ReportServerTempDB')
and replica_id Is NULL
FOR XML PATH('')), 1, 2, ''))
DECLARE @listenername varchar (100) = ''
if exists (select serverproperty('IsHADREnabled'))
BEGIN
SET @listenername = (select Listener_Name = STUFF((select ', ' + dns_name from sys.availability_group_listeners
FOR XML PATH('')), 1, 2, ''))
END

DECLARE @emailsubject varchar (100) = 'Attn: Database(s) not a member of AOAG on '+@servername
DECLARE @Email_body varchar(400) = 'This is an informational message only:
The below databases on '+ @servername +', are not in an AlwaysOn Availibility Group.

Database Name(s):
'+@Databases+'

Below is the list of configured Availability Group Listener(s)
'+@listenername

print @Email_body

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Your SQL Server Database Mail Account',
--@recipients = '',
@recipients = '',
--@copy_recipients = '',
@body = @Email_body,
@subject = @emailsubject;
END
END
GO

/**********************************************************************
* Name: Check_async_logins_and_alert.sql
* Created by: Arun Yadav
* Purpose: This script will check and e-mail if there are any logins which are present
* on a given availability replica and are missing from any other replicas.
* Updated By:
* Updated on:
* Comments:
* Disclaimer: Though the script has been tested, I do not take any guarantees,
* it is advised to test the scripts again before implementing in production
**********************************************************************/

use [master]
GO

CREATE PROCEDURE usp_Check_async_logins_and_alert
AS
BEGIN
SET NOCOUNT ON

DECLARE @replicas nvarchar(50), @Replica_List nvarchar(100)

SET @Replica_List = (SELECT Replica_name = STUFF((SELECT ', '+ replica_server_name from [sys].[availability_replicas]
FOR XML PATH('')), 1, 2, ''))
--print @Replica_List

DECLARE kursor cursor for
SELECT replica_server_name from [sys].[availability_replicas]
WHERE replica_server_name <> @@servername

OPEN kursor
FETCH NEXT FROM kursor INTO @replicas
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @login_qry nvarchar(600), @login_chk nvarchar(5)
SET @login_chk = 'SELECT count (name) from [sys].[server_principals]
WHERE name not in (SELECT name from ['+@replicas+'].[master].[sys].[server_principals])
and type not in (''C'', ''R'')
and name not like ''##%''
and name not like ''NT SERVICE%''
and name not like ''NT AUTHORITY%'''

SET @login_qry = 'SELECT name from [sys].[server_principals]
WHERE name not in (SELECT name from ['+@replicas+'].[master].[sys].[server_principals])
and type not in (''C'', ''R'')
and name not like ''##%''
and name not like ''NT SERVICE%''
and name not like ''NT AUTHORITY%'''
print @login_qry

if (@login_chk is not null)
BEGIN
DECLARE @servername sysname = (SELECT @@servername)
DECLARE @loginnames nvarchar (500)

CREATE TABLE #temp(name sysname)
INSERT INTO #temp
EXEC (@login_qry)
--SELECT * from #Temp
--Drop table #Temp

SET @loginnames = (SELECT name = STUFF((SELECT ', '+name from #temp
FOR XML PATH ('')), 1, 2, ''))

--print @loginnames

DECLARE @listenername nvarchar (100) = ''
if exists (SELECT serverproperty('IsHADREnabled'))
BEGIN
SET @listenername = (SELECT Listener_Name = STUFF((SELECT ', ' + dns_name from sys.availability_group_listeners
FOR XML PATH('')), 1, 2, ''))
END

DECLARE @emailsubject nvarchar (100) = 'Attn: Matching login not found on Availability replica: '+@replicas
DECLARE @Email_body nvarchar(1000) = 'This is an informational message only:
The below logins from instance: '+ @servername +' were not found on Availability replica: '+@replicas+'

Login Name(s):
'+@loginnames+'

Please create a login on all the availability replicas with the same SID.
Example to generate creation script for a specific login: Exec [dbo].[sp_help_revlogin]

Below is the list of configured Availability Group Listener(s):
'+@listenername+'

Below is the list of configured Availability Replicas:
'+@Replica_List

print @Email_body

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Your SQL Server Database Mail Account',
--@recipients = '',
@recipients = '',
--@copy_recipients = '',
@body = @Email_body,
@subject = @emailsubject;

Drop table #Temp
END
FETCH NEXT FROM kursor INTO @replicas
END

CLOSE kursor
DEALLOCATE kursor
END
GO

/**********************************************************************
* Name: Check_async_SQLAgent_jobs_and_alert.sql
* Created by: Arun Yadav
* Purpose: This script will check and e-mail if there are any sql agent jobs which are present
* on a given availability replica and are missing from any other replica(s).
* Updated By:
* Updated on:
* Comments:
* Disclaimer: Though the script has been tested, I do not take any guarantees,
* it is advised to test the scripts again before implementing in production
**********************************************************************/

use [master]
GO

CREATE PROCEDURE usp_Check_async_SQLAgent_jobs_and_alert
AS
BEGIN
SET NOCOUNT ON

DECLARE @replicas nvarchar(50), @Replica_List nvarchar(100)

SET @Replica_List = (SELECT Replica_name = STUFF((SELECT ', '+ replica_server_name from [sys].[availability_replicas]
FOR XML PATH('')), 1, 2, ''))
--print @Replica_List

DECLARE kursor cursor for
SELECT replica_server_name from [sys].[availability_replicas]
WHERE replica_server_name <> @@servername

OPEN kursor
FETCH NEXT FROM kursor INTO @replicas
WHILE @@FETCH_STATUS = 0
BEGIN

DECLARE @login_qry nvarchar(600), @jobcheck nvarchar(200)

SET @jobcheck = 'SELECT count (sj.name)
from msdb.dbo.sysjobs as sj
where sj.enabled = 1
and sj.name not in (SELECT rsj.name from ['+@replicas+'].[msdb].[dbo].[sysjobs] rsj
WHERE rsj.enabled = 1)
'
--print @jobcheck

SET @login_qry = 'SELECT sj.name
from msdb.dbo.sysjobs as sj
where sj.enabled = 1
and sj.name not in (SELECT rsj.name from ['+@replicas+'].[msdb].[dbo].[sysjobs] rsj
WHERE rsj.enabled = 1)
'
--print @login_qry

--if (isnumeric(@jobcheck) <> 0)
if (@jobcheck is not null)
BEGIN
print 'not null'
DECLARE @servername sysname = (SELECT @@servername)
DECLARE @jobnames nvarchar(2000)
CREATE TABLE #temp(name sysname)
INSERT INTO #temp
EXEC (@login_qry)
--SELECT * from #Temp
--Drop table #Temp

SET @jobnames = (SELECT name = STUFF((SELECT ', '+name from #temp
FOR XML PATH ('')), 1, 2, ''))

DECLARE @listenername nvarchar (100) = ''
if exists (SELECT serverproperty('IsHADREnabled'))
BEGIN
SET @listenername = (SELECT Listener_Name = STUFF((SELECT ', ' + dns_name from sys.availability_group_listeners
FOR XML PATH('')), 1, 2, ''))
END

DECLARE @emailsubject nvarchar (100) = 'Attn: Matching SQL Agent job not found on Availability replica: '+@replicas
DECLARE @Email_body nvarchar(1000) = 'This is an informational message only:
Below SQL Agent job(s) from instance: '+ @servername +' were not found on Availability replica: '+@replicas+'

Job Name(s):
'+@jobnames+'

These jobs will not run in case the replica '+ @servername +' goes down

Below is the list of configured Availability Group Listener(s):
'+@listenername+'

Below is the list of configured Availability Replicas:
'+@Replica_List

print @Email_body

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Your SQL Server Database Mail Account',
--@recipients = '',
@recipients = '',
--@copy_recipients = '',
@body = @Email_body,
@subject = @emailsubject

Drop table #Temp
END
ELSE
BEGIN
PRINT 'Jobs found'
END

FETCH NEXT FROM kursor INTO @replicas
END

CLOSE kursor
DEALLOCATE kursor
END
GO

/**********************************************************************
* Name: Check_async_SQLAgent_jobs_and_alert.sql
* Created by: Arun Yadav
* Purpose: This script will check and e-mail if there are any sql agent jobs which are present
* on a given availability replica and are missing from any other replica(s).
* Updated By:
* Updated on:
* Comments:
* Disclaimer: Though the script has been tested, I do not take any guarantees,
* it is advised to test the scripts again before implementing in production
**********************************************************************/

USE [msdb]
GO
DECLARE @jobId BINARY(16)
EXEC msdb.dbo.sp_add_job @job_name=N'AlwaysON-Async-Login-Job-DB-check',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=2,
@notify_level_netsend=2,
@notify_level_page=2,
@delete_level=0,
@description=N'Step 1 will check and e-mail if there are any databases which are not a part of Availability group.
Step 2 will check and e-mail if there are any logins which are present on a given availability replica and are missing from any other replica(s).
Step 3 will check and e-mail if there are any SQL Agent jobs which are present on a given availability replica and are missing from any other replica(s).',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
select @jobId
GO
EXEC msdb.dbo.sp_add_jobserver @job_name=N'AlwaysON-Async-Login-Job-DB-check', @server_name = @@servername
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_jobstep @job_name=N'AlwaysON-Async-Login-Job-DB-check', @step_name=N'Check_DBs_not_configured_in_AG',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=3,
@on_fail_action=2,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'exec dbo.usp_Check_DBs_not_configured_in_AG',
@database_name=N'master',
@flags=4
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_jobstep @job_name=N'AlwaysON-Async-Login-Job-DB-check', @step_name=N'Check_async_logins_and_alert',
@step_id=2,
@cmdexec_success_code=0,
@on_success_action=3,
@on_fail_action=2,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'exec dbo.usp_Check_async_logins_and_alert',
@database_name=N'master',
@flags=4
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_jobstep @job_name=N'AlwaysON-Async-Login-Job-DB-check', @step_name=N'Check_async_SQLAgent_jobs_and_alert',
@step_id=3,
@cmdexec_success_code=0,
@on_success_action=1,
@on_fail_action=2,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'TSQL',
@command=N'exec dbo.usp_Check_async_SQLAgent_jobs_and_alert',
@database_name=N'master',
@flags=4
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_update_job @job_name=N'AlwaysON-Async-Login-Job-DB-check',
@enabled=1,
@start_step_id=1,
@notify_level_eventlog=0,
@notify_level_email=2,
@notify_level_netsend=2,
@notify_level_page=2,
@delete_level=0,
@description=N'Step 1 will check and e-mail if there are any databases which are not a part of Availability group.
Step 2 will check and e-mail if there are any logins which are present on a given availability replica and are missing from any other replica(s).
Step 3 will check and e-mail if there are any SQL Agent jobs which are present on a given availability replica and are missing from any other replica(s).',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'sa',
@notify_email_operator_name=N'',
@notify_netsend_operator_name=N'',
@notify_page_operator_name=N''
GO

More »

 

Database Pros Who Need Your Help

Here's a few of the new posts today on the forums. To see more, visit the forums.


SQL Server 2017 - Administration
How to run a different account using SQL Job to execute powershell script - Hi All , I need to run powershell script which is located in other server, lets say server A . In server B , i created the SQL job .. What is the query that I need to put in Command area so I can run it as ( ABC\xxx ) and execute the script […]
SQL Server 2016 - Development and T-SQL
group records by week - I have a table , and I want to have a query that shows by week how many records are being created. I'm trying to pull the value from t_stamp like this just to see the value. SELECT dateadd(S, t_stamp, '1970-01-01 00:00:00') FROM #dataCapture Arithmetic overflow error converting expression to data type int. Insert Into […]
match near date based on another date - hello,  i am stuck and need some help to generate output based on the below scenario if object_id(N'tempdb..#t1') is not null DROP TABLE #t1 if object_id(N'tempdb..#t2') is not null DROP TABLE #t2 create table #t1 ( userid int, maildate date ) insert into #t1 select 1, '2021-05-04' union select 1, '2021-04-13' union select 1, '2020-11-03' […]
Administration - SQL Server 2014
dbmail failing to send intermittently - I'm using sp_send_dbmail to send mails to an Office 365 account. All mails have similar content and are sent to users in the same domain. All mails were sent using the same profile. About 50% of the mails were delivered and the rest failed to be sent. (Checked in the msdb.dbo.sysmail_allitems), the error is "The […]
Upgrade SQL and OS of legacy - Hi All, We are planning to upgrade both SQL and OS of legacy versions. We have the following. SQL 2000 and 2005 running on windows server 2003 SQL 2008R2 running on windows server 2008R2 Can anyone share suggestion, how to upgrade this. I believe we need to go one by one with intermediate versions. Can […]
SQL 2012 - General
SQL Server 2012 Standard Media/ISO - Does anyone have a copy of SQL Server 2012 Standard handy? I just need the ISO or DVD contents to install on a new server. I have the key already from the old server, but we don't have the media any longer. I checked online and can't seem to find a good place to download […]
SQL Server 2019 - Administration
Options to restrict users to select nothing but views only? - We have 2 databases Database1 and Database2 on the same server box that very tightly coupled. Database2 has views or sprocs that use the .schema.  naming convention to pull data from Database1. Lots of data in Database1 and Database2 are PHI data thus the need for data protection and security. We have a request to […]
SQL Server 2019 - Development
Export to Multiple Worksheets / Tabs in Excel ? - I am able to use an SSIS package to export from a SQL table and create an Excel spreadsheet and assign the Tab name. But I would like to export to multiple tabs within the same spreadsheet. For example, SELECT Fld1, Fld2 ,FLD3  from My_Table WHERE Color = 'BLUE' SELECT Fld1, Fld2 ,FLD3  from My_Table […]
Question about malformed ZIP codes - ISNULL('"' + LEFT(D.Zip, 5) + '"', '"99999"') AS ["Customer Zip"], I have this query in a stored procedure and use it for some EDI transactions.  In the past few months we received an alert from the vendor that our file was not processing.  In doing some research, there was a test account put into the […]
UNION ALL with CTE - Hello. I am trying to UNION ALL two tables 1) Current receipts 2) Historical receipts. Both of those tables have CTE because it was the only way how could it change numeric field into date field. This is my Current receipts table   ;WITH t AS (SELECT *, ProperDate = CASE WHEN ISDATE(CONVERT(char(8), r.RCLDTE)) = […]
SSIS Error - i figured it out.  please ignore post.
General Cloud Computing Questions
Are all learning resources just rote memorization? - Title says it all, recently got frustrated prepping for GCP's ACE with Qwiklabs because that's all it felt I was doing, just following steps, and for example altho in their Coursera courses they do explain some of the background as to why some of the components exist, I find its still missing why they need […]
Reporting Services
Clustered Standard Edition - Hi, I've inherited a two-node Windows Failover Cluster (SAN storage) with a SQL Cluster configured (Standard Edition) but where SSRS had been rather hopefully installed on both nodes as well.  If the SQL Cluster Role is on Node 1 then SSRS works but once it fails over to Node 2 it doesn't.  Once failed back […]
Analysis Services
restore SSAS Database on a share - file system error when opening file - Hi fellow DB colleagues In our company we explore ways to store SSAS multidimensional databases on fileshares instead of dedicated drives of servers. We use virtual servers. So I am testing the possibility to deploy SSAS databases on a fileshare. I run my test on a virtual server and a fileshare that are located in […]
SQLServerCentral.com Website Issues
No notifications are getting sent - I have not receiving email notifications for the various threads on forum posts.  There have been a number of replies I have posted, and no emails are getting sent for additional replies in the thread. They are not going to my spam folder.
 

 

RSS FeedTwitter

This email has been sent to {email}. To be removed from this list, please click here. If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com. This newsletter was sent to you because you signed up at SQLServerCentral.com.
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
webmaster@sqlservercentral.com

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -