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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 separating a value

Author  Topic 

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-04-23 : 06:36:49
Hi,
I have a string value that separated by dot character. And I have another two variables that I need to assignment left of string value to first variable and right part of dot character to second variable.
Example:
Declare @string varchar(20), @first varchar(15), @second varchar(15);
Set @string = ‘left.right’;
-- NEEDED STATEMNT
SELECT @first, @second;
--Result
-- left right


thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-23 : 06:40:36
[code]SELECT @first=PARSENAME(@string,2),
@second =PARSENAME(@string,1)
SELECT @first, @second;[/code]
------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-04-23 : 06:40:46
set @first=parsename('left.right',2)

set @second=parsename('left.right',1)

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-23 : 06:42:21
Declare @string varchar(20), @first varchar(15), @second varchar(15);
Set @string = 'left.right';
-- NEEDED STATEMNT
SELECT @first=SUBSTRING(@String,1,CHARINDEX('.',@string)-1),
@second=SUBSTRING(@String,CHARINDEX('.',@string)+1,LEN(@string))

select @first,@second


Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-23 : 06:42:56


Madhivanan

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

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-04-23 : 06:48:49
Thanks a lot.
(Remember me? [NOT] EXISTS() )
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-23 : 06:52:09
quote:
Originally posted by ms65g

Thanks a lot.
(Remember me? [NOT] EXISTS() )


Yes. Do you have any solution that invloves [NOT] EXISTS()

Also now-a-days, you are not very active here

Madhivanan

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

Sachin.Nand

2937 Posts

Posted - 2010-04-23 : 07:45:13
ms65g welcome back.
Nowadays you hardly seem to be very active on this forum.So any particular reason for such a long break???


PBUH
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-04-23 : 08:55:05
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=143434
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-23 : 08:57:27
quote:
Originally posted by ms65g

See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=143434


Dont stop replying just becuase someone finds mistakes in your code
You will learn over the period of time

Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-23 : 09:07:11
quote:
Originally posted by madhivanan

quote:
Originally posted by ms65g

See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=143434


Dont stop replying just becuase someone finds mistakes in your code
You will learn over the period of time

Madhivanan

Failing to plan is Planning to fail


It was not someone finding mistakes with his code
usually it was other way around
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=139575

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2010-04-23 : 09:39:18
quote:
Originally posted by madhivanan

quote:
Originally posted by ms65g

See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=143434


Dont stop replying just becuase someone finds mistakes in your code
You will learn over the period of time

Madhivanan

Failing to plan is Planning to fail


Now I will easily accept any advice.
Your recommends help me to write queries and code very efficient.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-23 : 10:05:27
quote:
Originally posted by ms65g

quote:
Originally posted by madhivanan

quote:
Originally posted by ms65g

See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=143434


Dont stop replying just becuase someone finds mistakes in your code
You will learn over the period of time

Madhivanan

Failing to plan is Planning to fail


Now I will easily accept any advice.
Your recommends help me to write queries and code very efficient.



You are welcome

Madhivanan

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

- Advertisement -