SELECT name, description
FROM sys.fn_helpcollations()
SELECT SERVERPROPERTY('collation')
Uma
You can achieve this in many ways, the easiest way is, use SELECT TOP 1 1 FROM TABLE
SELECT TOP 1 = Selecting the very 1st record in the result set
SELECT 1 = return 1 as the result set
SELECT TOP 1 1 FROM [SomeTable] WHERE <SomeCondition> Means if the condition is true and any rows are returned from the select, only return top 1 row and only return integer 1 for the row (no data just the integer 1 is returned).
Cheers!
Uma
These days most of the organizations use SFTP files transfer protocol. There is still no any inbuilt component in SSIS to download the files from SFTP, but there is a component for FTP.
Most of use C# or PowerShell code to avoid cost for 3rd party components. In this blog, I explain how to use PowerShell with WinScp. First you need to install WinSCP library and most of the code you can get from https://winscp.net/forum
Here is the example code to download the latest file using wildcard
<#####################
Code
######################>
#Parameters
$localPath = "D:\YourRemoteFolder\"
$remotePath = "/YourFolder/"
$fileName="MyFiles"
#Define Wildcard
$fileWildcard = $fileName + "_" + ".zip"
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "xx.xxx.xxx.xx"
UserName = "user1"
Password = "123456"
SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}
Try
{
$session = New-Object WinSCP.Session
# Connect
$session.Open($sessionOptions)
# Get list of files in the directory
$directoryInfo = $session.ListDirectory($remotePath)
# Select the most recent file
$latest =
$directoryInfo.Files |
Where-Object {$_.Name -like $fileWildcard } |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
Write-host $latest
$remotePathFull = $remotePath
# check the file exists
if ($latest -eq $Null)
{
Write-Host "No file found"
exit 0
}
else
{
# Download the selected file
$remotePathFull = $remotePath+$latest
#$session.GetFiles([WinSCP.RemotePath]::EscapeFileMask($latest.FullName), $localPath).Check()
$session.GetFiles($remotePathFull, $localPath).Check()
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}
<#####################
Code End
######################>
You can call this PowerShell script using Execute Process Task under SSIS
Cheers!
Uma
SSIS doesn’t come with any component to download the email attachments. The only way is use script task. You can use your own code or third-party libraries. If the business requirement is more complex I would recommend using third-part libraries rather write your own code. Limilabs Mail.dll .NET email component makes your jobs easy, you can read more details here https://www.limilabs.com/mail. You can find similar libraries and use it.
Add references and then add the following libraries based on your requirement
using Limilabs.Client.IMAP;
using Limilabs.Mail;
using Limilabs.Mail.Headers;
Cheers!
Uma
Once indexes are created, they will undergo automatic maintenance by the SQL Server Database Engine whenever insert, update or delete operations are executed on the underlying data. These automatic modifications will continuously scatter the information in the index throughout the database – fragmenting the index over time.
The result – indexes now have pages where logical ordering (based on the key-value) differs from the physical ordering inside the data file. This means that there is a high percentage of free space on the index pages and that SQL Server has to read a higher number of pages when scanning each index. Also, ordering of pages that belong to the same index gets scrambled and this adds more work to the SQL Server when reading an index – especially in IO terms.
The solution to fragmented indexes is to rebuild or reorganize indexes.
Index reorganization - Index reorganization is a process where the SQL Server goes through the existing index and cleans it up. While index reorganization is a pure clean-up operation that leaves the system state as it is without locking-out affected tables and views.
Index rebuild - index is deleted and then recreated from scratch with an entirely new structure, free from all piled up fragments and empty-space pages. the rebuild process locks the affected table for the whole rebuild period, which may result in long down-times that could not be acceptable in some environments
To decide which one to do, it is important to answer two main questions:
1. What is the degree of fragmentation?
2. What is the appropriate action? Reorganize or rebuild?
Detecting fragmentation information for an index or table or database
DECLARE @db_id SMALLINT;
DECLARE @object_id INT;
SET @db_id = DB_ID(N'AdventureWorks2017');
SET @object_id = OBJECT_ID(N'AdventureWorks2017.Person.Address');
IF @db_id IS NULL
BEGIN;
PRINT N'Invalid database';
END;
ELSE IF @object_id IS NULL
BEGIN;
PRINT N'Invalid object';
END;
ELSE
BEGIN;
SELECT * FROM sys.dm_db_index_physical_stats(@db_id, @object_id, NULL, NULL , 'LIMITED');
END;
GO
Generally accepted solution based on the percent of fragmentation - avg_fragmentation_in_percent column from the previously described sys.dm_db_index_physical_stats function.
Fragmentation is less than 10% – no de-fragmentation is required.
Fragmentation is between 10-30% – it is suggested to perform index reorganization
Fragmentation is higher than 30% – it is suggested to perform index rebuild
Using SQL Server Management Studio:
using Transact-SQL
Further details please read the following links
Cheers!
Uma