Solved

Reterieve the values in T-SQl

Posted on 2013-11-26
2
311 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now