November 22, 2012 at 8:57 pm
Comments posted to this topic are about the item STUFF - 1
November 22, 2012 at 10:29 pm
nice ๐ thank you for the question
(though it was simple and straight question, not sure why i kept occupied myself thinking as it was a trick question... :crazy:)
ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
November 22, 2012 at 10:54 pm
Thanks ,good question.. learn first time about STUFF and then answered it ๐
-----------------------------------------------------------------------------
เคธเคเคเฅเคค เคเฅเคเคฃเฅ
November 22, 2012 at 10:59 pm
Another question about different stuff ๐
An interesting example of inserting one string into another. Never thought it could be done that way. I always did it using something like
SELECT LEFT(@string1, 10) + @Stuffing + RIGHT(@string1, LEN(@string1) - 10)
November 22, 2012 at 11:07 pm
+1
November 23, 2012 at 12:46 am
Couldn't work out if it was a trick question or not - decided it wasn't
Thanks for the point and the question Ron
-------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. โ Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
November 23, 2012 at 12:49 am
Nice question to end the week. Thanks Ron!
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
November 23, 2012 at 1:16 am
vk-kirov (11/22/2012)
Another question about different stuff ๐An interesting example of inserting one string into another. Never thought it could be done that way. I always did it using something like
SELECT LEFT(@string1, 10) + @Stuffing + RIGHT(@string1, LEN(@string1) - 10)
STUFF is a very powerful function that can be used for many things, but unfortunately is not very well known. I have seen people struggle with RIGHT and REVERSE or SUBSTRING and LENGTH to cut off the first three characters of a string, instead of simply using STUFF(@string, 1, 3, '').
Ron, thanks for this question. I hope it helps spread the knowledge about STUFF.
November 23, 2012 at 1:27 am
This was removed by the editor as SPAM
November 23, 2012 at 2:08 am
Thanks for a good question, I know about STUFF for replacing parts of strings but thought the '0' for the length parameter formed part of a trick question (i.e. insert no characters from @stuffing rather than delete no characters from @string1) so selected 16, not 46.
Then after getting it wrong ๐ and researching the question I found this comment from Zafar Yousafi in BOL:
At first sight it might not be clear directly how to insert a character (or a string) instead of substituting characters in the original string.
To insert a string, without replacing/substituting characters in the original string you need to specify a length of 0 (zero).
SELECT STUFF('abcghi', 4, 0, 'DEF');
-- this results in 'abcDEFghi'.
So, learned something new today - thanks!
---
Note to developers:Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
My blog: http://uksqldba.blogspot.com
Visit http://www.DerekColley.co.uk to find out more about me.
November 23, 2012 at 2:10 am
There's an explanation of sorts here
http://msdn.microsoft.com/en-us/library/ms188043(SQL.105).aspx
(in the comments section at the end)
November 23, 2012 at 8:46 am
Nice question. I learned something new about T-SQL today. Thanks!
Andre Ranieri
November 23, 2012 at 10:28 am
kalyani.k478 (11/22/2012)
+1
+1 ๐
November 23, 2012 at 11:04 am
First, thank you for prodding me to read about STUFF, a function I'd seen mentioned but which I haven't used.
Your explanation of answer starts with
I could not find an explanation of the "lengthing" of the declared item....
This was the point I considered after reading the BOL entry and before choosing my answer. The given QOD code does not assign the modified value to either of the variables. The function may return data with a type inherited from the input, but the length of the function's output is not constrained by the lenghth of either input string. Consider what you may naturally expect if you were to add these lines to the end of the given script:
DECLARE @string2 VARCHAR(50)
set @string2 = STUFF(@string1, 11,0,@Stuffing)
select @string2
,len(@string2)
A truncated value of "Microsoft ******" or "Microsoft ********************" would hardly be acceptable.
November 23, 2012 at 12:54 pm
Nice question about a function that I do not use enough. Thanks for the question!
Viewing 15 posts - 1 through 15 (of 22 total)
You must be logged in to reply to this topic. Login to reply