Solved

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

Posted on 2009-05-03
3
425 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 250 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

730 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