Announcement

Collapse
No announcement yet.

nvarchar(MAX) im Cursor

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • nvarchar(MAX) im Cursor

    Hallo,

    ich benötige innerhalb eines Cursors eine Variable die mehr als 4000 Zeichen enthalten kann. Ich habe es mit nvarchar(max) versucht aber der Text innerhalb der Variablen wird bei 4000 Zeichen abgeschnitten.

    Ist das evtl. ein Bug? Die Doku gibt darüber irgendwie nichts her.

    Gruß,
    Andre

  • #2
    AS Designed. Ein Record im MS SQL Server kann für alle (n)varchars, integer, ... maximal 8060 Bytes umfassen.

    Google mal nach "8060 Bytes" oder such in der MSDN nach "8060" und du bekommst einiges an Hilfestellung

    Comment


    • #3
      Hallo Andre,

      nvarchar(max) fast schon 2^31 -1 Bytes (also 2^31 -1 nZeichen).
      Allerdings wollen nvarchr(max) Typen besonders behandelt werden; Beispiel:
      [highlight=SQL]DECLARE @txt nvarchar(max);
      SET @txt = REPLICATE(N'X', 9000);
      SET @txt = @txt + REPLICATE(N'Y', 9000)
      SELECT LEN(@txt)

      CREATE TABLE #txt (txt varchar(max));
      INSERT INTO #txt VALUES(REPLICATE(N'X', 4000));

      UPDATE #txt
      SET txt .Write(REPLICATE(N'Y', 9000), LEN(txt), NULL)
      UPDATE #txt
      SET txt .Write(REPLICATE(N'Z', 9000), LEN(txt), NULL)

      SELECT LEN(txt) FROM #txt;
      DROP TABLE #txt[/highlight]
      Ergebnis:
      8000
      12000

      Man bekommt so also immer nur eine Page = 8060 Bytes an Daten rein.
      Olaf Helper

      <Blog> <Xing>
      * cogito ergo sum * errare humanum est * quote erat demonstrandum *
      Wenn ich denke, ist das ein Fehler und das beweise ich täglich

      Comment


      • #4
        Bei Zeichenfolgefunktionen und nvarchar(MAX) muss man selber richtig casten:

        DECLARE @txt nvarchar(max)

        SET @txt = REPLICATE(N'X', 9000)
        SELECT LEN(@txt) ... liefert 4000 (weil automatisch nur auf nvarchar() gecastet wird)

        SET @txt = REPLICATE(cast('X' as nvarchar(MAX)), 19000)
        SELECT LEN(@txt) ... liefert 19.000!

        bye,
        Helmut

        Comment

        Working...
        X