473,788 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

overflowing a local varchar

If I declare a local variable in a cursors query and append values to
it with successiuve concatenations, how come SQL7 does not report an
error if I concatenate a value to it that will overflow it's declared
size? Specifically,

DELCARE @t varchar(5)

....

SET @t = '12345'

....

SET @t = @t + '1 more'

The concatenation of '1 more' does not signal an error. In fact, you
can do any number of successive concatenations and none of them will
report an error.

Shouldn't SQL7 be reporting an error?
Jul 20 '05 #1
3 2165
Well, it will report an error if you try to insert a value larger than the
actual field size.

Like this:

create table Tst (c varchar(5))
insert into Tst values('123456' )

If you run it you'll get this result:

Server: Msg 8152, Level 16, State 9, Line 1
String or binary data would be truncated.
The statement has been terminated.

So if the value of your local variable is going to be stored in a table, and
if you are changing this value in a way that it can grow, it's not a bad
idea to use bigger variables and then check the result of INSERT or UPDATE
statements.

Shervin
"Zack Sessions" <zc********@vis ionair.com> wrote in message
news:db******** *************** ***@posting.goo gle.com...
If I declare a local variable in a cursors query and append values to
it with successiuve concatenations, how come SQL7 does not report an
error if I concatenate a value to it that will overflow it's declared
size? Specifically,

DELCARE @t varchar(5)

...

SET @t = '12345'

...

SET @t = @t + '1 more'

The concatenation of '1 more' does not signal an error. In fact, you
can do any number of successive concatenations and none of them will
report an error.

Shouldn't SQL7 be reporting an error?

Jul 20 '05 #2
Hello,

It will just rim off the excess part without throwing an error. It's
similarly handled in SQL 2k too.

-Manoj
Jul 20 '05 #3
Zack Sessions (zc********@vis ionair.com) writes:
If I declare a local variable in a cursors query and append values to
it with successiuve concatenations, how come SQL7 does not report an
error if I concatenate a value to it that will overflow it's declared
size? Specifically,

DELCARE @t varchar(5)

...

SET @t = '12345'

...

SET @t = @t + '1 more'

The concatenation of '1 more' does not signal an error. In fact, you
can do any number of successive concatenations and none of them will
report an error.

Shouldn't SQL7 be reporting an error?


Maybe it should, but it doesn't. :-)

You get an error if you try to put too much into a table column and
you are running with ANSI_WARNINGS ON. But variables never traps this
error.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
21160
by: Robin Tucker | last post by:
I want to look at the size of the current database, so I can create a new one if it gets too big (we are working around the 2gb MSDE limit for our customers). I would like to do something like this: DECLARE @size INTEGER execute BLOB0000.dbo.sp_spaceused
7
4785
by: James o'konnor | last post by:
hello. i have the next for create one table into db2 CREATE TABLE "MYSQUEMA"."TABLADEMO" ( "ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH +0 INCREMENT BY +1 MINVALUE +0 MAXVALUE +2147483647 NO CYCLE
9
5896
by: Marty McFly | last post by:
Greetings, I'm trying to let my users dynamically filter records from a table that relate to other tables. RELATIONSHIPS: . = . . = . There is a Many-to-Many relationship between CustomersTable and
1
11263
by: bhavin.vyas | last post by:
Friends, I would just like to know that why SQL Server doen't allow us to define a text data type local variable while creating trigger? I tried creating a text variable in a trigger as a local variable and it raises error. "Implicit conversion from data type text to nvarchar is not allowed. Use the CONVERT function to run this query".
2
40570
by: John Smith | last post by:
What is the difference? Is LONG VARCHAR only 28 bytes longer then VARCHAR? Is this the only difference?
2
16421
by: gderosa | last post by:
Hey guys I need some help with local variables, here is my current code: CREATE PROCEDURE CreateFile AS DECLARE @notification int SET @notification = (SELECT NotificationPeriod FROM Notification Where NotificationID = 1) SET NOCOUNT ON --Populate template
0
27261
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications are constrained by the technology available at the time of their development and hence aren’t optimum as per current scenario. One of such cases is the extensive usage of CHAR fields, which aren’t optimum solution for space storage now. This paper...
3
1384
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi, I have a form with TabControl and a TabPage in it. In the tag control there is panel control (lets call it panelA) and in it my user control that include few control inside of it. In my development computer everything looks fine. But on some other computers, the panelA control is overflowing outside the right boundary of the TabPage together with all of its child controls.
4
1546
by: RakuRay | last post by:
I am having trouble with dynamic SQL. Early in my code I assign data to a bunch of local variables. I want to access these later in my code and use the data values. The code example below shows a simplified example to explain what I am trying to do. -- ---------------------------------------------- -- Declare and set the data into a local variable -- ---------------------------------------------- DECLARE @SD1 real SET @SD1 = 1.1
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8995
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.