question

ABHISHEKSAQL avatar image
ABHISHEKSAQL asked

Need Help with SP

Dear Members, I need to fetch records based on particular type(FFRT-TR= ) and then replace it. For example below are the record types 20017546 FFRT-TR= 3456 TT:SX 2398 FFRT-TR=6532 I need to fetch records which contains FFRT-TR= and then replace the whole the of FFRT-TR=3456 Required Output based on the above examples: 20017546(for 1st example) 2398(for 2nd example) Please help. Thanks in advance
stored-proceduresreplacecharindexsp
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Steve Jones - Editor avatar image
Steve Jones - Editor answered

It's not completely clear what you mean. I assume that you have two rows here? As in:

RowID Value

1 20017546 FFRT-TR= 3456 TT:SX

2 2398 FFRT-TR=6532

Please give some DDL like this when you post:

CREATE TABLE SPHelp
( RowID INT
, Rowvalue VARCHAR(200)
)
GO
INSERT dbo.SPHelp
(
  RowID ,
  Rowvalue
)
VALUES
  (1, '20017546 FFRT-TR= 3456 TT:SX')
, (2, ' 2398 FFRT-TR=6532')

If this is the case, then you can use CHARINDEX to find the location of your FFRT. For example, if I wrote

SELECT CHARINDEX('FFRT-TR=', sh.Rowvalue)
FROM dbo.SPHelp AS sh;

I'd get 10 and 7. Those are the character location where that string starts. If I then combine that with SUBSTRING, I could do:

SELECT SUBSTRING(sh.Rowvalue, 1, CHARINDEX('FFRT-TR=', sh.Rowvalue) - 1)
FROM dbo.SPHelp AS sh;

This gives me just the first part of the string.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.