Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reterieve the values in T-SQl

Posted on 2013-11-26
2
Medium Priority
?
324 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

877 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