Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

String or binary data would be truncated. Expand / Collapse
Author
Message
Posted Tuesday, September 25, 2012 8:24 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 8:49 PM
Points: 81, Visits: 930
I am getting error in below code:


SET NOCOUNT ON

CREATE TABLE #EVENTS (LOGDATE DATETIME, PROCESSINFO VARCHAR(50), VCHMESSAGE VARCHAR(800), SOURCE VARCHAR(20), CROW INT)

-- CHECK FOR SQL INSTALLATION WHETHER IF 2000 OR 2005 --
-- IN CASE OF 2000, XP_READERRORLOG GIVES ONLY SQL SERVER LOGS AND OUTPUTS ONLY 2 COLUMNS --
-- IN CASE OF 2005, XP_READERRORLOG GIVES BOTH SQL SERVER AND AGENT LOGS --

IF (SELECT LEFT(CAST(SERVERPROPERTY('PRODUCTVERSION') AS VARCHAR),1)) = 8
BEGIN
INSERT INTO #EVENTS (VCHMESSAGE, CROW) EXEC XP_READERRORLOG

UPDATE #EVENTS SET LOGDATE = SUBSTRING(VCHMESSAGE,1,19), PROCESSINFO = 'SERVER', SOURCE = 'SQL SERVER'
WHERE SUBSTRING(VCHMESSAGE,1,3)='200' and substring(VCHMESSAGE,5,5)='-'

END
ELSE
BEGIN
INSERT INTO #EVENTS (LOGDATE, PROCESSINFO, VCHMESSAGE) EXEC XP_READERRORLOG 0,1 -- CURRENT LOGS, SQL SERVER
UPDATE #EVENTS SET SOURCE = 'SQL SERVER'

INSERT INTO #EVENTS (LOGDATE, PROCESSINFO, VCHMESSAGE) EXEC XP_READERRORLOG 0,2 -- CURRENT LOGS, SQL SERVER AGENT
UPDATE #EVENTS SET SOURCE = 'SQL SERVER AGENT' WHERE SOURCE IS NULL
END







The error which i am getting is :
Msg 8152, Level 16, State 2, Procedure xp_readerrorlog, Line 1
String or binary data would be truncated.

Please if some can help......
Post #1364400
Posted Wednesday, September 26, 2012 1:10 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 6:48 PM
Points: 20,734, Visits: 32,499
I'd say you need to expand the size of one or more of your varchar columns. Not sure which but that's where I'd start. My google-fu isn't very strong today.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1364466
Posted Wednesday, September 26, 2012 1:28 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 8:49 PM
Points: 81, Visits: 930
It got resolved by changing VCHMESSAGE VARCHAR(800)

to VCHMESSAGE VARCHAR(max)
Post #1364478
Posted Wednesday, September 26, 2012 7:57 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:56 PM
Points: 13,081, Visits: 12,545
That is one of the most irritating things about sql server. There is a connect issue somewhere to change the message of that error to include the column name. DUH!!! Of course the engine knows which column threw the error, not returning it in the error message is just sad.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1364699
Posted Thursday, September 27, 2012 7:30 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, March 6, 2014 1:35 AM
Points: 175, Visits: 547
Hi,

Before inserting the data, find out what the MAX(LEN(Col)) is for each column. Compare the results to your variable declarations and destination table design.

Btw, varchar(max) isn't recognized in SQL 2000. Better find out what it needs to be at the moment and add a little buffer. But if must be as big as possible use varchar(8000) instead.

Goodluck.




For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
Post #1365250
Posted Thursday, September 27, 2012 7:35 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:56 PM
Points: 13,081, Visits: 12,545
D.Post (9/27/2012)
Hi,

Before inserting the data, find out what the MAX(LEN(Col)) is for each column. Compare the results to your variable declarations and destination table design.

Btw, varchar(max) isn't recognized in SQL 2000. Better find out what it needs to be at the moment and add a little buffer. But if must be as big as possible use varchar(8000) instead.

Goodluck.


varchar(4000) is the largest size in sql 2000.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1365258
Posted Thursday, September 27, 2012 8:58 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, March 6, 2014 1:35 AM
Points: 175, Visits: 547
Oops!
Thanks Sean!
Haven't used it in many years.




For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
Post #1365328
Posted Thursday, September 27, 2012 10:00 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 6:06 AM
Points: 3,761, Visits: 8,440
I disagree, varchar can hold up to 8000 characters in 2000 (nvarchar will only hold up to 4000, though).

http://msdn.microsoft.com/en-us/library/aa258242(SQL.80).aspx

Another option is to use text columns



Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1365363
Posted Thursday, September 27, 2012 11:54 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:56 PM
Points: 13,081, Visits: 12,545
Luis Cazares (9/27/2012)
I disagree, varchar can hold up to 8000 characters in 2000 (nvarchar will only hold up to 4000, though).

http://msdn.microsoft.com/en-us/library/aa258242(SQL.80).aspx

Another option is to use text columns


Doh!!! You are right Luis, thanks for the correction to my incorrect correction.

I too haven't 2000 in a long long time.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1365425
Posted Thursday, September 27, 2012 12:10 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 6:06 AM
Points: 3,761, Visits: 8,440
Sean Lange (9/27/2012)
Luis Cazares (9/27/2012)
I disagree, varchar can hold up to 8000 characters in 2000 (nvarchar will only hold up to 4000, though).

http://msdn.microsoft.com/en-us/library/aa258242(SQL.80).aspx

Another option is to use text columns


Doh!!! You are right Luis, thanks for the correction to my incorrect correction.

I too haven't 2000 in a long long time.


I remember the number because of the 8K Splitter.
I just had to find the reference to confirm it.



Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1365437
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse