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.
Author |
Topic |
urzsuresh
Starting Member
30 Posts |
Posted - 2010-08-16 : 03:26:52
|
Hello friends I have table employeefor eg1 Ramesh2 Rahul I need output like this1 r1 a1 m1 e1 s1 h2 r2 a2 h2 u2 l I need bring this result,without using functions and loop.how can i achieve this. can anyone please suggest me through sample codeSuri |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-16 : 03:42:01
|
[code]DECLARE @Sample TABLE ( ID INT, Name VARCHAR(20) )INSERT @SampleSELECT 1, 'Ramesh' UNION ALLSELECT 2, 'Rahul'SELECT s.ID, LOWER(f.theChar) AS theCharFROM @Sample AS sCROSS APPLY ( SELECT SUBSTRING(s.Name, v.Number, 1), v.Number FROM master..spt_values AS v WHERE v.Type = 'P' AND v.Number BETWEEN 1 AND DATALENGTH(s.Name) ) AS f(theChar, thePosition)ORDER BY s.ID, f.thePosition[/code] N 56°04'39.26"E 12°55'05.63" |
 |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-08-16 : 03:44:45
|
Try this too..Declare @i intDeclare @name varchar(25)set @i=1While (@i<=2)BeginSelect @name=name from #temp where id=@i While(len(@name)>0) Begin Select @i as id,left(@name,1) as name set @name=right(@name,len(@name)-1) Endset @i=@i+1EndSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-08-16 : 04:36:54
|
quote: Originally posted by senthil_nagore Try this too..Declare @i intDeclare @name varchar(25)set @i=1While (@i<=2)BeginSelect @name=name from #temp where id=@i While(len(@name)>0) Begin Select @i as id,left(@name,1) as name set @name=right(@name,len(@name)-1) Endset @i=@i+1EndSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
how can this be applied on the table data ?Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-16 : 04:49:21
|
quote: Originally posted by vaibhavktiwari83 how can this be applied on the table data ?
The code assumes the data is already in the #Temp table. N 56°04'39.26"E 12°55'05.63" |
 |
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-08-16 : 05:19:15
|
quote: Originally posted by Peso
quote: Originally posted by vaibhavktiwari83 how can this be applied on the table data ?
The code assumes the data is already in the #Temp table. N 56°04'39.26"E 12°55'05.63"
Ohh I misunderstood something but still.It will give different result set rather than rows in one result set, won't it ?Vaibhav TTo walk FAST walk ALONE To walk FAR walk TOGETHER |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-08-16 : 05:34:03
|
Yes, Senthil's suggestion will give you one resultset for every character.My suggestion will give one resultset for all characters. Quite a difference. N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|
|