How to print string value in horizantally in sql server

Posted by Karthik2010_Mca under Interview Questions on 2/24/2013 | Points: 10 | Views : 1303 | Status : [Member] | Replies : 3
How to print string value in horizantally in sql server

Ex,
DECLARE @Name VARCHAR(50)
SET @Name = "WELCOME"

I want output like this below
W
E
L
C
O
M
E

Karthik


Responses

Posted by: Murugavelmsc on: 2/24/2013 [Member] Starter | Points: 25

Up
0
Down
loop through the string

new line = char(12)


Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Karthik2010_Mca, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/24/2013 [Member] Starter | Points: 25

Up
0
Down
DECLARE @string VARCHAR(50)
DECLARE @wcount INT
DECLARE @index INT
DECLARE @len INT
DECLARE @char varchar(10)
SET @string = 'welcome'
SET @wcount= 0
SET @index = 1
SET @len= LEN(@string)
WHILE @index<= @len
BEGIN
set @char = SUBSTRING(@string, @index, 1)
print @char
SET @index= @index+ 1
END




Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Karthik2010_Mca, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthik2010_Mca on: 2/24/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Murugavel,

It is very useful for me.
Thanks lot.

Karthik

Karthik2010_Mca, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response