Posts

How To Find the ASCII Value of each character in your String – SQL Server

  Here’s a simple query that lists the ASCII Value of each character in your string in SQL Server DECLARE @counter int = 1 ; DECLARE @colString varchar ( 10 ) = 'AA%#& ' ; WHILE @counter <= DATALENGTH ( @colString ) BEGIN SELECT CHAR ( ASCII ( SUBSTRING ( @colString , @counter , 1 ))) as [Character] , ASCII ( SUBSTRING ( @colString , @counter , 1 )) as [ASCIIValue] SET @counter = @counter + 1 END GO  

How to get decimal value in a string using sql server

CREATE FUNCTION [dbo].[ udf_GetNumericValue ] (@strAlphaNumeric VARCHAR(256)) RETURNS VARCHAR(256) AS BEGIN DECLARE @intAlpha INT SET @intAlpha = PATINDEX('%[^0-9.]%', @strAlphaNumeric) BEGIN WHILE @intAlpha > 0 BEGIN SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' ) SET @intAlpha = PATINDEX('%[^0-9.]%', @strAlphaNumeric ) END END RETURN ISNULL(@strAlphaNumeric,0) END -- SELECT   dbo.[udf_GetNumericValue]('CAD 7 810.50') Output : 7810.50

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...

Get Hourly Created records count for a day from a SQL Table

SELECT STUFF(RIGHT(CONVERT(VARCHAR,Createddate,0),7),3,3,' ') + ' - ' + STUFF(RIGHT(CONVERT(VARCHAR,DATEADD(HOUR,1,Createddate),0),7),3,3,' ') AS HOUR, COUNT(*) AS COUNT FROM tableName WHERE Createddate BETWEEN CONVERT(DATETIME,FLOOR(CONVERT(FLOAT,GETDATE()))) AND CONVERT(DATETIME,FLOOR(CONVERT(FLOAT,GETDATE())) + 1) GROUP BY STUFF(RIGHT(CONVERT(VARCHAR,Createddate,0),7),3,3,' ') + ' - ' + STUFF(RIGHT(CONVERT(VARCHAR,DATEADD(HOUR,1,Createddate),0),7),3,3,' ') ORDER BY 1

How to track column value change in sql server

CREATE TRIGGER [dbo].[TGRName] ON [dbo].[TableName] AFTER UPDATE AS BEGIN SET NOCOUNT ON; IF (UPDATE([ColumnName])) INSERT INTO [TableName]([Columns]....) Select distinct [Columns].... from INSERTED I INNER JOIN Deleted D ON D.Id= I.Id WHERE I.[ColumnName] <> D.[ColumnName] SET NOCOUNT OFF END