how to select next n letters after one specific letter using function in sql server by giving function name,specific letter, no of letters next

Mixture of CHARINDEX with SUBSTRING if on SQL Server. DECLARE @Text VARCHAR(100) = ‘The cat is under the table.’ DECLARE @CharToSearch CHAR = ‘s’ DECLARE @CharactersToRetrieve INT = 5 SELECT CharacterPosition = CHARINDEX(@CharToSearch, @Text), TrimmedString = SUBSTRING( @Text, CHARINDEX(@CharToSearch, @Text) + 1, @CharactersToRetrieve) Result: CharacterPosition TrimmedString 10 unde

How do i split strings in SQL server? [duplicate]

CREATE FUNCTION [dbo].[fnSplitString] ( @string NVARCHAR(MAX), @delimiter CHAR(1) ) RETURNS @output TABLE(splitdata NVARCHAR(MAX) ) BEGIN DECLARE @start INT, @end INT SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) WHILE @start < LEN(@string) + 1 BEGIN IF @end = 0 SET @end = LEN(@string) + 1 INSERT INTO @output (splitdata) VALUES(SUBSTRING(@string, @start, @end – @start)) SET … Read more

How to multiply column in Sql

If number1 is a value from first row and number2 is value from next row, then use ROW_NUMBER(): ;WITH cte AS ( SELECT col, ROW_NUMBER() OVER (ORDER BY (SELECT 1)) as rn FROM (VALUES (-0.75640390000), (0.58303570000), (-0.07794400000), (0.00000000000), (0.58303570000), (-0.07794400000), (0.42976550000), (0.58781540000), (0.00909080000), (0.58781540000) ) as t(col) ), rec AS ( SELECT CAST((1+col/100) as float) … Read more

Where clause not working in sql server

Let’s try creating a self-contained example – the below code works fine for me. Can you insert some sample data from your application into this toy code and see if it runs as you expect? If it does, then the problem lies elsewhere in your code. CREATE TABLE #TempReceivingUnmatchedUPCs ( RecUPC VARCHAR(20), RecSupplierInvoiceNumber VARCHAR(20), Foobar … Read more