Teams Login Error: login_hint duplicated

Clear everything for teams in your credential manager.

Restart Team.

Advertisements

Get a Parameter Value from Linkedserver Query Sample (EXEC (‘….’) AT linkerservername )

  

declare @cnt int
EXECUTE (' Use Projects;
SELECT
?= SUM(p.row_count) 
FROM sys.dm_db_partition_stats p
JOIN sys.objects o ON o.object_id = p.object_id
JOIN sys.schemas s ON o.schema_id = s.schema_id
WHERE p.index_id <2 AND o.type = ''U''
AND s.name = ''dbo''
 AND o.name = ''Reports''
',@cnt output

  ) AT  [RemoteServer]

 select @cnt

  

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/141016f1-84d9-4c84-9006-431bdb91fea8/exec-at-query-syntax-question?forum=transactsql
Relevant documentation part:

[?]
Indicates parameters for which values are supplied in the <arg-list> of pass-through commands that are used in an EXEC(‘…’, <arg-list>) AT <linkedsrv> statement.

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/execute-transact-sql?view=sql-server-2017



Download File with Start-BitsTransfer

  

$url = "https://www.myfilesource,com/datafile.xls"
$output = "C:\SourceDataDownload\mynewdatafile.xls"

Start-BitsTransfer -Source $url -Destination $output

 

https://docs.microsoft.com/en-us/powershell/module/bitstransfer/start-bitstransfer?view=win10-ps


View Definition of Stored Procedure

  

SELECT   [object_id]
      ,[definition] 
  FROM myDatabase.[sys].[all_sql_modules] asm
  where exists(
  select * from sys.all_objects ao
where type='P'  and asm.[object_id]= ao.[object_id])
 and asm.[object_id]>0 

  

Check SQL Server Instance Installed Datetime

 --- Run this query

SELECT min(create_date) create_date
FROM sys.server_principals
Where type_desc='WINDOWS_LOGIN'


Cannot drop database “” because it is currently in use.

  

 --The query to find the spid for the db in use
 declare @spid smallint
 select  @spid= convert (smallint, req_spid)  
      from master.dbo.syslockinfo l, 
           master.dbo.spt_values v,
           master.dbo.spt_values x, 
           master.dbo.spt_values u, 
           master.dbo.sysdatabases d
      where   l.rsc_type = v.number 
      and v.type = 'LR' 
      and l.req_status = x.number 
      and x.type = 'LS' 
      and l.req_mode + 1 = u.number
      and u.type = 'L' 
      and l.rsc_dbid = d.dbid 
      and rsc_dbid = (select top 1 dbid from 
                      master..sysdatabases 
                      where name = 'mydb')

declare @kill_process nvarchar(2000) 
SET @kill_process =  N'KILL ' +Cast(@spid as nvarchar(10)) 

--kill the db in use process
EXEC master.dbo.sp_executesql @kill_process
 PRINT 'killed spid : '+ Cast(@spid as nvarchar(10)) 

Go

if db_id('mydb') is not null
alter database mydb 
set single_user with rollback immediate;
go
--rename database to another name
sp_renamedb 'mydb', 'mydb_old'

go
--drop the db with the new name
DROP DATABASE mydb_old 

  

Find Null percentage in each Column of Each Table in a DB

  

 Create  procedure [dbo].[usp_CountNullFromEachTable]
 
 @SCHEMA_TABLE_NAME NVARCHAR(100)  
 as

 
SET NOCOUNT ON;
  DECLARE @sql NVARCHAR(4000),
 @col NVARCHAR(50)
 
DECLARE c_cursor CURSOR FOR
  SELECT column_Name
  FROM   [INFORMATION_SCHEMA].[COLUMNS]
  WHERE  TABLE_NAME = parsename(@SCHEMA_TABLE_NAME,1)
         AND TABLE_SCHEMA = parsename(@SCHEMA_TABLE_NAME,2)
         AND IS_Nullable = 'YES'
OPEN c_cursor;
FETCH NEXT FROM c_cursor INTO @col;
WHILE ( @@FETCH_STATUS = 0 )
  BEGIN
      SET @sql = N' INSERT INTO CountNullFromEachTable (ColName, [NULL%], SCHEMA_TABLE_NAME)
        SELECT TOP 1 ''' + @col
                 + ''' , (COUNT(*) over() *1.0- COUNT(' + Quotename(@col) 
                 + ') OVER()*1.0)/NULLIF(COUNT(*) Over() ,0) *100.0 as [NULL%], '''
				 +@SCHEMA_TABLE_NAME+''' FROM '
                 + @SCHEMA_TABLE_NAME
 
      EXEC (@sql);
      FETCH NEXT FROM c_cursor INTO @col;
  END
CLOSE c_cursor;
DEALLOCATE c_cursor;
 
 


  IF (EXISTS (SELECT 1 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'CountNullFromEachTable'))
BEGIN
   drop table dbo.CountNullFromEachTable
END

 CREATE TABLE dbo.CountNullFromEachTable
  (
     id      INT IDENTITY(1, 1),
     ColName VARCHAR(50),
     [NULL%] DECIMAL(8, 2)
	 ,SCHEMA_TABLE_NAME NVARCHAR(50)
  )

  
SET ANSI_WARNINGS OFF;
exec sp_msforeachtable "exec dbo.[usp_CountNullFromEachTable] '?' "
--or
--exec sp_msforeachtable 'exec dbo.[usp_CountNullFromEachTable] ''?'' '


SELECT ColName,  [NULL%], SCHEMA_TABLE_NAME 
FROM dbo.CountNullFromEachTable




  

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ac43bf15-9bbb-4051-af87-f8638204fc2e/how-can-i-find-percentage-nulls-in-each-field-in-each-table-in-a-sql-server-db?forum=transactsql