Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

708 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

20 Experts available now in Live!

Get 1:1 Help Now