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 2008 Forums
 Transact-SQL (2008)
 How to extract characters ???

Author  Topic 

shantanu88d
Starting Member

35 Posts

Posted - 2011-03-22 : 01:29:29
I have a variable which will have following values
set @purchase_date = 'Jan 1 2011 12:00AM,Jan 2 2011 12:00AM,Jan 3 2011 12:00AM'

I want to separate dates one by one...which function and how can I use it ???
Please HELP !

stepson
Aged Yak Warrior

545 Posts

Posted - 2011-03-22 : 02:53:42
use charindex

select substring(@purchase_date,1,charindex(',',@purchase_date,1)-1)
set @purchase_date = substring(@purchase_date,charindex(',',@purchase_date,1)+1,len(@purchase_date)-charindex(',',@purchase_date,1))
select @purchase_date

put them in a while if are more dates
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-22 : 04:25:24
Searcyh for Split function in this forum

Madhivanan

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

- Advertisement -