Solved

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

Posted on 2009-05-03
3
416 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
  • 2
3 Comments
 
LVL 142

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 142

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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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 to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now