|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 4:14 AM
Points: 1,384,
Visits: 4,876
|
|
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)
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Saturday, June 15, 2013 11:53 AM
Points: 280,
Visits: 212
|
|
Nice question. I learned something new about T-SQL today. Thanks!
Andre Ranieri
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 5:32 PM
Points: 3,508,
Visits: 2,588
|
|
kalyani.k478 (11/22/2012) +1 +1
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Monday, June 10, 2013 7:59 PM
Points: 1,491,
Visits: 3,010
|
|
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.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: 2 days ago @ 6:13 AM
Points: 2,598,
Visits: 1,551
|
|
| Nice question about a function that I do not use enough. Thanks for the question!
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 2:28 PM
Points: 538,
Visits: 119
|
|
Nice Stuff.
T-SQL is Great
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 4:53 PM
Points: 7,182,
Visits: 7,281
|
|
Nice question - and a reminder to me to use STUFF more often.
I don't understand why the explanation worries about the result length. . I agree with John Arnott's comments above about this. String functions either do or don't have a length parameter, and the ones that don't have a resulting length that can be any valid length (except MAX, unless a parameter of the function is declared with length MAX). Why should anyone expect STUFF to behave differently from + in this respect?
Tom Is minic a gheibheann béal oscailte dorn dúnta. Is minig a cheapas beul fosgailte dòrn dùinte.
http://es.linkedin.com/in/tomthomsonsoftware
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 4:40 AM
Points: 1,130,
Visits: 1,277
|
|
nice question for the week.. +1  learn about STUFF today
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: 2 days ago @ 6:18 AM
Points: 691,
Visits: 1,104
|
|
| Thanks for the STUFF question.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 2:15 PM
Points: 471,
Visits: 485
|
|
Nice question and I learned STUFF.
Aigle de Guerre!
|
|
|
|