Solved

Reterieve the values in T-SQl

Posted on 2013-11-26
2
317 Views
Last Modified: 2013-11-26
Hi Team,

I want to achieve the below result in T-SQL
ex:

@t='Country|Aug|BA.2|1|N/A'

I want to replace BA.2 dynamically, that's means any values after 2nd "|" can be replaced by my another variables.
0
Comment
Question by:prashant04
2 Comments
 
LVL 37

Accepted Solution

by:
ValentinoV earned 500 total points
ID: 39677712
Something like this?

declare @t varchar(1000) = 'Country|Aug|BA.2|1|N/A';
declare @replacementValue varchar(1000) = 'something new';

with PipePosition as (
	select CHARINDEX('|', @t, CHARINDEX('|', @t)+1) PositionOfSecondPipe
		, CHARINDEX('|', @t, CHARINDEX('|', @t, CHARINDEX('|', @t)+1)+1) PositionOfThirdPipe
)
select REPLACE(@t
	, SUBSTRING(@t, PositionOfSecondPipe+1, PositionOfThirdPipe - PositionOfSecondPipe-1)
	, @replacementValue)
from PipePosition

Open in new window

0
 

Author Comment

by:prashant04
ID: 39677787
Thanks for the solution its working!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
Introduction In the following article I’ll be discussing and demonstrating several different ways of how images can be put on a report. I’m using SQL Server Reporting Services 2008 R2 CTP, more precisely version 10.50.1352.12, but the methods ex…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question