473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using a variable in VARCHAR

Has anyone successfully used a variable in the length parameter of VARCHAR? I need to append a comment to a long field that often already has a string in it. I'm checking the length of the field, then I want to append my comment to the end. Below is what I'd like to do, but it only works if I use a literal in place of @LEN in the SET COMMENTS statement:

DECLARE @ADD1 AS VARCHAR(15)
DECLARE @LEN AS INT
SET @ADD1 = 'This is a test.'
SELECT @LEN = LEN(CONVERT(VARCHAR(1000),COMMENTS)) FROM PS_EX_SHEET_HDR WHERE SHEET_ID = '0000000080'
PRINT @LEN
UPDATE PS_EX_SHEET_HDR
SET COMMENTS = CONVERT(VARCHAR(@LEN),COMMENTS) + @ADD1 + @ADD2
WHERE SHEET_ID = '0000000080'
Nov 15 '11 #1
1 1607
gpl
152 100+
VarChar is a variable length type, it takes up just enough room to hold the contents (up to the limit in its declaration.

If you were using the Char type, then the length is important.

In your case just declare it as VarChar(4096) - and no, you cannot have variable variable-length declaration
Nov 16 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: bofh | last post by:
I'm working on a project where I need to store a CGI query in a database field. The query contains variables which will be substitued at runtime (e.g., today's date, key to select upon, etc), and...
1
by: Justin | last post by:
I have the following insert statement: "INSERT INTO Queue(CustomerId, Status, QueueId, Type, January) VALUES (@CustomerId" + ", @Status, @QueueId, @Type, @January); SELECT uId, CustomerId,...
1
by: kelvinweb | last post by:
Hi All, Is it possible to using variable store container.dataitem in ItemTemplate ?? For example. <ItemTemplate> <% Dim x x = container.dataitem("LineNo")
2
by: 张韡武 | last post by:
We have preffered language set as variable in xslt: <xsl:variable name="preferred_language"> zh </xsl:variable> Data: <name xml:lang="de">Raw Materials (Mining incl.)</name> <name...
2
by: MCOOP | last post by:
Is there a way to have a declare variable (@where) be used as the WHERE clause in a stored procedure? The reason I ask is that I'm trying to use one sql statement for several possible WHERE...
6
by: mike | last post by:
so I keep optimizing my fields down to the minimum character length necessary i.e., varchar(15), then I find out a month later its gotta get bigger, then a few months later, bigger again, etc. ...
9
by: Chad | last post by:
This might be a bit vague and poorly worded..... In my program, I handle function failures using fprintf() and exit() like: fprintf(stderr, "malloc failed"); exit(EXIT_FAILURE); There...
3
by: sunilkes | last post by:
Hello I am a newbie to this, so I would appreciate any help, I am struggling to get this to work CREATE PROCEDURE . @strfinalint as varchar(1000), @startdate as datetime @enddate as datetime
1
by: ragonz | last post by:
Hi, i'm kind of newbie in java programming. Now, i'm working on my task, n i hav a problem in using variable from other method. Here goes the code.. import java.awt.*; import java.awt.event.*;...
1
by: smartic | last post by:
how can i assign value to static var inside class using variable variables technique ex: self::$$var = $value;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.