all groups > sql server programming > november 2007 >
You're in the

sql server programming

group:

Setting Maximum Column length in Stored Procedure


Setting Maximum Column length in Stored Procedure Jeff Swanberg
11/2/2007 6:20:59 PM
sql server programming: Using SQL Server 2K

TableA with two columns:
StudentID Int (PK)
ATTENDANCE char(7000)

TableB has seven columns:
StudentID Int
ATTEND1 varchar(254)
ATTEND2 varchar(254)
ATTEND3 varchar(254)
ATTEND4 varchar(254)
ATTEND5 varchar(254)
ATTEND6 varchar(254)

I want to insert into TableA a single entry from a concatenation of TableB:

INSERT INTO TableA
select
StudentID, (ATTEND1+ATTEND2+ATTEND3+ATTEND4+ATTEND5+ATTEND6) as ATTENDANCE
from
TableB

This only works in Query Analyzer, though, if I go to Tools-Options-Results
and change the "Maximum characters per column" value to 7000. If I don't,
then the only value that gets put into TableA's ATTENDANCE column is the
first 256 characters of the concatenation.

I would like to run this in a DTS package or Stored Procedure and I'm not
sure how to make that same maximum character change programmatically.

Jeff

Re: Setting Maximum Column length in Stored Procedure Mark J. McGinty
11/2/2007 9:30:21 PM
(Expressly avoiding discussion of your design...) why don't you just define
a computed column on TableB? Then you can skip the need to keep it updated,
it will always be current. One possible drawback, if you're using any
SELECT * queries, is that the addition of the computed column might blow out
the 8060 limit, but since you really should avoid that anyway...

Just a thought,
Mark


[quoted text, click to view]

Re: Setting Maximum Column length in Stored Procedure Jeff Swanberg
11/2/2007 9:41:31 PM
Hi Mark,

The table structure comes from an off-the-shelf product that our school
district uses so I can't change the design nor add another field to the
table. I really just need to find a way to programmatically allow for the
concatenation of the fields in a DTS package so that no truncatation occurs.

js

[quoted text, click to view]

Re: Setting Maximum Column length in Stored Procedure Erland Sommarskog
11/3/2007 12:00:00 AM
Jeff Swanberg (j_swanberg@msn.com) writes:
[quoted text, click to view]

You are confusing vision and fact. The setting in Query Analyzer is
only a display setting. The data is never truncated in the database.
So just sleep tight, this will not be an issue in your DTS package or
stored procedure.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
AddThis Social Bookmark Button