Geeks Talk

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.

One row to Multiple Rows

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+ ...

Go Back   Geeks Talk > Databases > SQL Server
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

SQL Server SQL Server is a Database Management System(DBMS) by Microsoft

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-15-2009
Junior Member
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kkknnn is on a distinguished road
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.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-15-2009
Contributing Member
 
Join Date: Jun 2009
Location: United States
Posts: 71
Thanks: 0
Thanked 5 Times in 4 Posts
CSOOR is on a distinguished road
Re: One row to Multiple Rows

Quote:
Originally Posted by kkknnn View Post
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.

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
Reply With Quote
Reply

  Geeks Talk > Databases > SQL Server

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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


All times are GMT -4. The time now is 12:35 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved