Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on One row to Multiple Rows within the SQL Server forums, part of the Databases category; Hi, If i have one table with one row, how to break it by delimiter to get multiple rows from that. Example: Source Table T1 +++++++++++++++ +My Name is Raghav+ ...
|
|||||||
| SQL Server SQL Server is a Database Management System(DBMS) by Microsoft |
![]() |
| LinkBack | Thread Tools | Display Modes |
|
|||
|
One row to Multiple Rows
Hi,
If i have one table with one row, how to break it by delimiter to get multiple rows from that. Example: Source Table T1 +++++++++++++++ +My Name is Raghav+ +++++++++++++++ Final Table ++++++++ +My + +Name + +is + +Raghav + ++++++++ I want delimited by Space. |
| Sponsored Links |
|
|||
|
Re: One row to Multiple Rows
Quote:
CREATE FUNCTION dbo.Split(@String varchar(8000), @Delimiter char(1)) returns @temptable TABLE (items varchar(8000)) as begin declare @idx int declare @slice varchar(8000) select @idx = 1 if len(@String)<1 or @String is null return while @idx!= 0 begin set @idx = charindex(@Delimiter,@String) if @idx!=0 set @slice = left(@String,@idx - 1) else set @slice = @String if(len(@slice)>0) insert into @temptable(Items) values(@slice) set @String = right(@String,len(@String) - @idx) if len(@String) = 0 break end return end /*--------Compile the above code in your server and test with below select statement , here delimiter is ',' --------*/ select * from dbo.split('Chennai,Bangalore,Mumbai',',') There is no other way, you will have to split thro' logic. Hope this will help |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| First 3 rows | SURJYA SAHOO | Oracle | 2 | 03-06-2009 02:11 AM |
| how to get Latest rows? | myaung | SQL Server | 1 | 01-01-2009 10:08 AM |
| can we lock rows of a table so that not any instance can even select that rows? | UditaOra | Oracle | 3 | 07-31-2008 08:32 AM |
| how to move the particular rows or multiple rows in gridview are selected using check | gnanadesigan.k | ASP.NET | 1 | 07-18-2008 08:39 AM |
| Duplicating one row into two rows | JobHelper | Data Warehousing | 7 | 07-11-2007 02:16 AM |