• 0

[SQL] Varchar cutting off my string!


Question

Ive got a long stored proc that adds several strings to a varchar variable at different steps then outputs the full varchar result at the end.

Its adding the first 2 strings to the varchar, but it only adds half of the 3rd one and none of the 4th one.

I thought maybe the varchar variable was full... but ive set it to VARCHAR(8000) and when i do a LEN() on the final varchar variabl its only 269.

Anyone know why its cutting off the end of my varchar!?!?

(Using SQL Server 2000 btw)

Link to comment
https://www.neowin.net/forum/topic/319106-sql-varchar-cutting-off-my-string/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

This is really annoying me now... here is some code... ne1 see whats wrong?

DECLARE	@NewsMessage  VARCHAR(8000)

SELECT	@NewsMessage = 'Battle Report from Planet ' + PlanetName +  '[' + CAST(XPos AS VARCHAR(3)) + ':' + CAST(YPos AS VARCHAR(3)) + ':' + CAST(ZPos AS VARCHAR(3)) + '].<BR>'
FROM	tblAccount
WHERE	AccountID = @AccIDUnderAttack

SELECT	@NewsMessage = @NewsMessage + 'Defending Fleets: ' + CAST(@DefendFleets AS VARCHAR(5)) + '<BR>Defending Ship Quantity: ' + CAST(@DefendTotalShips AS VARCHAR(15)) + '<BR>Defending Ship Luck: ' + CAST(@DefendLuck AS VARCHAR(5)) + '<BR>Defending Ship Loss: ' + CAST(@DefendShipLoss AS VARCHAR(15)) + '<BR>'

SELECT	@NewsMessage = @NewsMessage + 'Attacking Fleets: ' + CAST(@AttackFleets AS VARCHAR(5)) + '<BR>Attacking Ship Quantity: ' + CAST(@AttackTotalShips AS VARCHAR(15)) + '<BR>Attacking Ship Luck: ' + CAST(@AttackLuck AS VARCHAR(5)) + '<BR>Attacking Ship Loss: ' + CAST(@AttackShipLoss AS VARCHAR(15)) + '<BR>'

  • 0

Found out what was goin on...

I was using MS SQL Server 2000's Query Analyser application to retrieve these results. It appears the Query Analyser application only lets you display 260 odd characters per line in the results window. And rather than indicate that it had cut off the result from the results pane, and rather than continuing on the line below, it just stops out putting the data.

So there is no problem when i run it cos i can see the correct long varchar result in my application (which doesnt limit the result output!).

I hope they do something about this for SQL Server 2005's Query Analyser... very dodgy...

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.