-1

I have a column with names

name

Jason Mark

I am looking to get an output like

Split

J
a
s
o
n
M
a
r
k

Is it possible to perform the above in a single SQL statement irrespective of the length of the string. The platform I work is MSSQL server.

  • SQL is not used to that kind of operations. Do that in your logic. – juergen d Apr 02 '14 at 17:11
  • I just want to know if it is possible? It is okay if you do't know the answer! – infestation Apr 02 '14 at 17:12
  • it's possible, but not in a simple select, you'd need to write a stored procedure, and even then it's likely not recommended – fnostro Apr 02 '14 at 17:13
  • So in a simple select statement it is not possible to do the above? Hmmmm..... – infestation Apr 02 '14 at 17:15
  • possible duplicate of [Turning a Comma Separated string into individual rows](http://stackoverflow.com/questions/5493510/turning-a-comma-separated-string-into-individual-rows) –  Apr 02 '14 at 17:15
  • 1
    @infestation: I know that it is ok if I do not know the answer. Thank you. The point is: SQL is not used for such data manipulation. Don't do it. Use another language for it like Java or C#... – juergen d Apr 02 '14 at 17:17
  • I know you should't do it. SQL has a different purpose. But this question was like kind of a itch I wanted to scratch, never gone use it in production. – infestation Apr 02 '14 at 17:35
  • @ Vladimir Oselsky I said using a simple select statement, how can it be a duplicate? The link you have posted is a different context. – infestation Apr 02 '14 at 17:38

1 Answers1

0

You can, but not with a single SELECT statement.

A relatively easy way to do it would be using a SQLCLR stored procedure that will make the query, manipulate the resultset in a .NET language like C# and return it as any other resultset.

You also could do some serious TSQL-fu in a traditional stored proc that will loop through your data and store every characters in a memory table that will thereafter be returned as the resultset.

If you ask if it can be done in a single SELECT statement without using functions or procedures of any kind, then the answer is: it's not possible. And as juergen mentions in the comments above, it shouldn't be the job of the server to manipulate data in such a way.

Crono
  • 10,211
  • 6
  • 43
  • 75