Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sting parse

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-02-07 : 04:24:16
hi team, i have string like '111111~2222~klk' ~ sign is seprator for each item, i need to set values of each item in
variables @v1 , @v2 , @v3 , plese help

challenge everything

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-02-07 : 04:31:22
declare @v1 varchar(10)
declare @v2 varchar(10)
declare @v3 varchar(10)
declare @test varchar(255)
set @test = '111111~2222~klk'
select
@v1=parsename(replace(@test,'~','.'),3),
@v2=parsename(replace(@test,'~','.'),2),
@v3=parsename(replace(@test,'~','.'),1)

select @v1,@v2,@v3



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-02-07 : 04:45:21
may contain any null value then


challenge everything
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-02-07 : 05:01:25
If you can give better examples then maybe we can give better solutions...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-02-07 : 05:02:12
'111111~2222~klk' IS NOW '111111~2222~'

challenge everything
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-02-07 : 05:08:40
declare @v1 varchar(10)
declare @v2 varchar(10)
declare @v3 varchar(10)


declare @test varchar(255)
set @test = '111111~2222~'
select
@v1=replace(parsename(replace(@test,'~','.~'),3),'~',''),
@v2=replace(parsename(replace(@test,'~','.~'),2),'~',''),
@v3=replace(parsename(replace(@test,'~','.~'),1),'~','')


select @v1,@v2,@v3



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-02-07 : 05:50:46
gr8, now there is more than one row seprated by ^ like 'dsdsds~sdsds~fsdsd^sdsd~dsds~^dsds~hdjfhjdh~dsd' then i need to get each row how can this be possible


challenge everything
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-02-07 : 06:47:52
What is "spoon feeding"?

Most often on the forums, "spoon feeding" refers to posters who ask questions, and refuse to put any effort or thought into their questions, as well as the answers they receive. They expect every answer to be dumbed down to the last detail, and expect that everyone else do their research for them.

This is usually a characteristic of laziness, and not capability. Hence the saying, "I'm not handicapped, I'm just lazy."


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-02-07 : 09:11:34
HOW CAN U DEFINE THE LAZYNESS, WHEN PEOPLE HAVE NO ANSWER THEN THEY TALK LIKE THAT..

AND THE WAY THE FORUM IS ABOUT THE EXPERIENCE SHARING, AND NOT FOR RESEARCH.

challenge everything
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-02-07 : 09:21:56
Please don't shout at me...

I am not in the mood to answer a question again and again if it will be expanded after each given answer.
Please don't be too lazy to describe your problem in a way that we don't have to guess about so many things.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-02-07 : 14:06:38
Do bear in mind that we are all unpaid volunteers posting in our spare time. If you want a useful solution, post the full description of the problem. Adding in complications again and again works fine in a mystery novel, but not when you're asking people for free help.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-02-13 : 12:57:08
What are you going to do with splitted values? You may need something like this
http://beyondrelational.com/blogs/madhivanan/archive/2008/09/11/splitting-delimited-data-to-columns-set-based-approach.aspx

If you are passing delimited values as parameter, you may need to use a differenct approach

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-13 : 13:18:09
Did you design this "database"?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -