December 2, 2014 at 5:20 am
Use the excellent splitter function by Jeff Moden[/url] and use a space as the delimiter.
Sort the results in descending order and concatenate them back together[/url].
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
December 2, 2014 at 6:07 am
Just and only for fun, here is a slightly twisted solution, recommend following Koen's suggestion
😎
DECLARE @STR VARCHAR(100)='My name is Shiva';
DECLARE @XSTR VARCHAR(MAX) = 'SELECT(SELECT CHAR(32)+Y.XN FROM(SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS XI,XN FROM (VALUES'+
CHAR(40)+CHAR(39)+REPLACE(@STR,CHAR(32),CHAR(39)+CHAR(41)+CHAR(44)+CHAR(40)+CHAR(39))+CHAR(39)+CHAR(41)+') AS X(XN)) AS Y ORDER BY Y.XI DESC
FOR XML PATH(''''),TYPE).value(''.[1]'',''varchar(100)'')';
EXEC (@XSTR);
Result
Shiva is name My
December 2, 2014 at 6:11 am
Eirikur Eiriksson (12/2/2014)
Just and only for fun, here is a slightly twisted solution, recommend following Koen's suggestion😎
DECLARE @STR VARCHAR(100)='My name is Shiva';
DECLARE @XSTR VARCHAR(MAX) = 'SELECT(SELECT CHAR(32)+Y.XN FROM(SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS XI,XN FROM (VALUES'+
CHAR(40)+CHAR(39)+REPLACE(@STR,CHAR(32),CHAR(39)+CHAR(41)+CHAR(44)+CHAR(40)+CHAR(39))+CHAR(39)+CHAR(41)+') AS X(XN)) AS Y ORDER BY Y.XI DESC
FOR XML PATH(''''),TYPE).value(''.[1]'',''varchar(100)'')';
EXEC (@XSTR);
Result
Shiva is name My
If you want people to be able to understand your code, follow my suggestion 😀
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
December 2, 2014 at 6:17 am
Koen Verbeeck (12/2/2014)
Eirikur Eiriksson (12/2/2014)
Just and only for fun, here is a slightly twisted solution, recommend following Koen's suggestion😎
DECLARE @STR VARCHAR(100)='My name is Shiva';
DECLARE @XSTR VARCHAR(MAX) = 'SELECT(SELECT CHAR(32)+Y.XN FROM(SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS XI,XN FROM (VALUES'+
CHAR(40)+CHAR(39)+REPLACE(@STR,CHAR(32),CHAR(39)+CHAR(41)+CHAR(44)+CHAR(40)+CHAR(39))+CHAR(39)+CHAR(41)+') AS X(XN)) AS Y ORDER BY Y.XI DESC
FOR XML PATH(''''),TYPE).value(''.[1]'',''varchar(100)'')';
EXEC (@XSTR);
Result
Shiva is name My
If you want people to be able to understand your code, follow my suggestion 😀
time next the mind in that keep will I:hehe:
😎
December 2, 2014 at 10:10 pm
Hi Mr. Eirikur Eiriksson
Its working fine and exactly it is what i need.
so thank you very much...
Thanks,
Shiva N
Database Consultant
December 3, 2014 at 12:19 am
Shiva N (12/2/2014)
Hi Mr. Eirikur EirikssonIts working fine and exactly it is what i need.
so thank you very much...
Do you also understand the code? If it crashes on your production server, people will ask you questions and you are responsible.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
December 3, 2014 at 12:35 am
Koen Verbeeck (12/2/2014)
Eirikur Eiriksson (12/2/2014)
Just and only for fun, here is a slightly twisted solution, recommend following Koen's suggestion😎
DECLARE @STR VARCHAR(100)='My name is Shiva';
DECLARE @XSTR VARCHAR(MAX) = 'SELECT(SELECT CHAR(32)+Y.XN FROM(SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS XI,XN FROM (VALUES'+
CHAR(40)+CHAR(39)+REPLACE(@STR,CHAR(32),CHAR(39)+CHAR(41)+CHAR(44)+CHAR(40)+CHAR(39))+CHAR(39)+CHAR(41)+') AS X(XN)) AS Y ORDER BY Y.XI DESC
FOR XML PATH(''''),TYPE).value(''.[1]'',''varchar(100)'')';
EXEC (@XSTR);
Result
Shiva is name My
If you want people to be able to understand your code, follow my suggestion 😀
+1 😀
December 3, 2014 at 9:21 am
twin.devil (12/3/2014)
Koen Verbeeck (12/2/2014)
Eirikur Eiriksson (12/2/2014)
Just and only for fun, here is a slightly twisted solution, recommend following Koen's suggestion😎
DECLARE @STR VARCHAR(100)='My name is Shiva';
DECLARE @XSTR VARCHAR(MAX) = 'SELECT(SELECT CHAR(32)+Y.XN FROM(SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS XI,XN FROM (VALUES'+
CHAR(40)+CHAR(39)+REPLACE(@STR,CHAR(32),CHAR(39)+CHAR(41)+CHAR(44)+CHAR(40)+CHAR(39))+CHAR(39)+CHAR(41)+') AS X(XN)) AS Y ORDER BY Y.XI DESC
FOR XML PATH(''''),TYPE).value(''.[1]'',''varchar(100)'')';
EXEC (@XSTR);
Result
Shiva is name My
If you want people to be able to understand your code, follow my suggestion 😀
+1 😀
Ooops, my bad:Whistling:, that's almost readable, here's a !fix
😎
DECLARE @STR VARCHAR(100)='My name is Shiva';
DECLARE @XSTR VARCHAR(MAX) = REPLICATE(0x53454C4543542853454C4543542043484152283332292B592E584E2046524F4D2853454C45435420524F575F4E554D4245522829204F56455220284F52444552204259202853454C454354204E554C4C29292041532058492C584E2046524F4D202856414C5545532827,1)+
REPLACE(@STR,0x20,0x27292C2827)+LTRIM(0x272929204153205828584E29292041532059204F5244455220425920592E5849204445534320464F5220584D4C2050415448282727292C54595045292E76616C756528272E5B315D272C277661726368617228313030292729);
EXEC (@XSTR);
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply