Solved

Reterieve the values in T-SQl

Posted on 2013-11-26
2
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
While in ##Table - Help 4 22
PolyServe for SQL server 13 41
query optimization 6 21
SQL- GROUP BY 4 21
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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