?
Solved

Returning varchar(8000) only allowing a return of 4000 characters

Posted on 2009-05-03
3
Medium Priority
?
427 Views
Last Modified: 2012-05-06
Can someone explain why the following proc is only returning 4000 characters?  QA is set to 8192, btw.  If I run a len on the retval it returns 4000 characters when there are about 5000 worth of the columns I am returning.

declare @retval varchar(8000)
   select @retval = coalesce(@retval + ',', '') + '[' + column_name + ']' from information_schema.columns where table_name = @table_name and column_name not in (@skipcols) order by column_name
   select @retval
0
Comment
Question by:crudmop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 24290764
column names are nvarchar, where the max is 4000 indeed.

declare @retval varchar(8000)
   select @retval = coalesce(@retval + ',', '') + '[' + cast(column_name as varchar(200)) + ']' from information_schema.columns where table_name = @table_name and column_name not in (@skipcols) order by column_name
   select @retval

Open in new window

0
 

Author Closing Comment

by:crudmop
ID: 31577357
doh doh doh.

Ya know I stared at this wondering what the hell was up.  You win the "let me make fun of you by pointing out the obvious" award.

Thanks much :)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24290801
<Author Comments>
doh doh doh.

Ya know I stared at this wondering what the hell was up. You win the "let me make fun of you by pointing out the obvious" award.
</Author Comments>

sorry, but that is not obvious "per se", as it's the typical case of implicit data type conversion, which are difficult to "see". as from some months/years of experience you remember things like those, and first search in that directly.

glad I could help to "un"-doe this :)

Cheers
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question