Posts

Showing posts from May, 2016

How to Get First Day and Last Day of a Current Quarter in SQL Server

To get the first day of the current quarter : SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0) To get the last day of the current quarter : SELECT DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +1, 0)) To get the first day of the previous quarter SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) - 1, 0) To get the last day of the previous quarter : SELECT DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0)) To get the first day of the next quarter : SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) + 1, 0) To get the last day of the next quarter : SELECT DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +2, 0))

SQL Query to extract the filename and file extension from the file path

    DECLARE @PathFile varchar(512)     SET @PathFile = '\sample.txt'     SELECT     FileName = REVERSE(LEFT(REVERSE(@PathFile), CHARINDEX('\', REVERSE(@PathFile), 1) - 1))     ,     FileExtension = REVERSE(LEFT(REVERSE(@PathFile), CHARINDEX('.', REVERSE(@PathFile), 1) - 1))

How to upload File to Secured FTP ( SFTP ) in C#

Upload File from Local Machine to SFTP Server in C# The following C# code will upload a file from local machine to SFTP server. string _ftpURL = "testsftp.com"; //Host URL or address of the SFTP server string _UserName = "admin"; //User Name of the SFTP server string _Password = "admin123"; //Password of the SFTP server int _Port = 22; //Port No of the SFTP server (if any) string _ftpDirectory = "Receipts"; //The directory in SFTP server where the files will be uploaded string LocalDirectory = "D:\\FilePuller"; //Local directory from where the files will be uploaded string FileName = "test.txt"; //File name, which one will be uploaded Sftp oSftp = new Sftp(_ftpURL, _UserName, _Password); oSftp.Connect(_Port); oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory + "/" + FileName); oSftp.Close();   tamir.sharpssh.dll can be downloaded from below link. https://sourcef