2016-11-15 2 views
4
PRINT Convert(VarChar(Max),Replicate('1234567890 ',1000)) 

Cela revient à la fenêtre 7997 caractères.SQL Server 2008 VarChar (Max) renvoie seulement 8000 caractères. Pourquoi?

SELECT Convert(VarChar(Max),Replicate('1234567890 ',1000)) 

Cela revient à la grille 7996 caractères. Le caractère supplémentaire dans la fenêtre d'impression est un CRLF. J'ai mes options en tant que telles: Outils → Options → Résultats de la requête → Résultats au texte → Nombre maximum de caractères affichés dans chaque colonne = 8192

Donc, je voudrais attendre 8 192 caractères à retourner dans la grille, et je voudrais Attendez-vous à ce que 11 001 caractères soient retournés à ma fenêtre.

Ensuite, il y a ce test:

DECLARE @VarCharMax VarChar(Max) 
SET @VarCharMax = Replicate('123456',2000) 
SELECT Right(@VarCharMax,3) -- returns 456 
SELECT Right(Left(@VarCharMax,8000),3) -- returns 456 
SELECT Right(Left(@VarCharMax,7999),3) -- returns 456 
SELECT Right(Left(@VarCharMax,7998),3) -- returns 456 
SELECT Right(Left(@VarCharMax,7997),3) -- returns 345 
SELECT Right(Left(@VarCharMax,7996),3) -- returns 234 

Qu'est-ce que je manque à comprendre ici? Il ne semble pas se comporter du tout comme je m'attendrais?

Répondre

4

8000 caractères est une limitation de la fonction répliquées à moins que l'argument est de type varchar (max)/nvarchar (max)

https://msdn.microsoft.com/en-us/library/ms174383.aspx

Si expression_chaîne est pas de type varchar (max) ou nvarchar (max), REPLICATE tronque la valeur de retour à 8 000 octets. Pour renvoyer des valeurs supérieures à 8 000 octets, string_expression doit être explicitement converti en le type de données de grande valeur approprié.

+1

Par défaut, il tronque à 8K, mais vous pouvez augmenter les résultats. c'est-à-dire en utilisant varchar (max) comme OP l'a fait – scsimon

+1

La distribution n'est pas au résultat mais à l'argument –

+1

Oui ... vous avez édité votre message après mon commentaire. – scsimon

2
SELECT len(Replicate(cast('1234567890' as varchar(max)),1000)) 

Returns 10000 
+3

Peut-être que vous devriez ajouter quelques explications. –

+0

@JuanCarlosOropeza La réponse initiale de Dudu était simplement "8000 caractères est une limitation de la fonction répliquée". J'illustrais qu'il y a un travail facile. –

1

votre texte '123456' intérieur de la fonction répliquées n'est pas varchar (max) de type de données. Comme Dudu a mentionné la fonction répliquée comme limitation pour 8000 caractères si l'expression n'est pas un type de données varchar (max).

0

Dudu l'a expliqué clairement. La chaîne ci-dessous contient 9 060 caractères.

DECLARE @VarCharMax VarChar(Max) 
SET @VarCharMax = 'This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!' 
PRINT Right(@VarCharMax,3) -- returns st! 
PRINT Right(Left(@VarCharMax,8000),3) -- returns is 
PRINT Right(Left(@VarCharMax,7999),3) -- returns his 
PRINT Right(Left(@VarCharMax,7998),3) -- returns Thi 
PRINT Right(Left(@VarCharMax,7997),3) -- returns !Th 
PRINT Right(Left(@VarCharMax,7996),3) -- returns t!h 

Cela revient comme je m'attendais.

+0

OK, ... ce genre de travail?!?! Il l'évalue correctement en mémoire, mais la déclaration d'impression et le retour à la grille sont toujours limités à 7 997 caractères. Je digresse pour ne pas fermer cette question, car je ne vois pas que cela a déjà été répondu. –

+1

* Les résultats sur Grille * et * Résultats sur Texte * sont limités par les options que vous avez sélectionnées, dans l'OP. Les cellules non XML ont une limite supérieure de [65 535 caractères] (https://msdn.microsoft.com/en-us/library/ms190078.aspx). [Print] (https://msdn.microsoft.com/en-us/library/ms176047.aspx?f=255&MSPPError=-2147217396) est limité à 8 000 caractères. Autant que je sache; c'est une limite dure, sans solution de contournement. –