Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Server text column question

SQL Server text column question

Scheduled Pinned Locked Moved Database
questiondatabasesql-serversysadminhelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcus Spitzmiller
    wrote on last edited by
    #1

    Hi - I just have a general SQL server question I'm hoping someone can help answer. I have a table with a column of datatype TEXT called NOTE. I am trying to trim those records in the text field to say, 10000 characters where datalength(NOTE) > 10000. for example, normally i would do something like 'update notetable set note = LEFT(note, 10000) where length(note) > 10000', but of course i can't do this with this datatype. This datatype is a pain..Does anyone know the syntax for this? Thanks!

    Marcus Spitzmiller You will never hear me say, "I listen to pretty much everything." That is for people who don't care what goes in their ears.

    P M 2 Replies Last reply
    0
    • M Marcus Spitzmiller

      Hi - I just have a general SQL server question I'm hoping someone can help answer. I have a table with a column of datatype TEXT called NOTE. I am trying to trim those records in the text field to say, 10000 characters where datalength(NOTE) > 10000. for example, normally i would do something like 'update notetable set note = LEFT(note, 10000) where length(note) > 10000', but of course i can't do this with this datatype. This datatype is a pain..Does anyone know the syntax for this? Thanks!

      Marcus Spitzmiller You will never hear me say, "I listen to pretty much everything." That is for people who don't care what goes in their ears.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Convert to/from VARCHAR?

      M 1 Reply Last reply
      0
      • P PIEBALDconsult

        Convert to/from VARCHAR?

        M Offline
        M Offline
        Marcus Spitzmiller
        wrote on last edited by
        #3

        No - it'll still ultimately reside in the same column - I just need to trim it. any thoughts?

        Marcus Spitzmiller You will never hear me say, "I listen to pretty much everything." That is for people who don't care what goes in their ears.

        E 1 Reply Last reply
        0
        • M Marcus Spitzmiller

          No - it'll still ultimately reside in the same column - I just need to trim it. any thoughts?

          Marcus Spitzmiller You will never hear me say, "I listen to pretty much everything." That is for people who don't care what goes in their ears.

          E Offline
          E Offline
          Eric Dahlvang
          wrote on last edited by
          #4

          I don't see why what PIEBALDconsult suggested will not work:

          select cast(mytextcolumn as varchar(1000)) as MyTextColumnTrimmed from mytesttable

          Try it out.

          --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

          M 1 Reply Last reply
          0
          • E Eric Dahlvang

            I don't see why what PIEBALDconsult suggested will not work:

            select cast(mytextcolumn as varchar(1000)) as MyTextColumnTrimmed from mytesttable

            Try it out.

            --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

            M Offline
            M Offline
            Marcus Spitzmiller
            wrote on last edited by
            #5

            I guess I misunderstood the suggestion. However, I did: select cast(NOTE as varchar(16349)) as NOTE from S_NOTE_ACCNT WHERE datalength(NOTE) > 16349 and I get: The size (16349) given to the type 'varchar' exceeds the maximum allowed for any data type (8000). So really, I need to trim the field to 16349, but apparently I can't this way...any thoughts?

            Marcus Spitzmiller You will never hear me say, "I listen to pretty much everything." That is for people who don't care what goes in their ears.

            1 Reply Last reply
            0
            • M Marcus Spitzmiller

              Hi - I just have a general SQL server question I'm hoping someone can help answer. I have a table with a column of datatype TEXT called NOTE. I am trying to trim those records in the text field to say, 10000 characters where datalength(NOTE) > 10000. for example, normally i would do something like 'update notetable set note = LEFT(note, 10000) where length(note) > 10000', but of course i can't do this with this datatype. This datatype is a pain..Does anyone know the syntax for this? Thanks!

              Marcus Spitzmiller You will never hear me say, "I listen to pretty much everything." That is for people who don't care what goes in their ears.

              M Offline
              M Offline
              Michael Potter
              wrote on last edited by
              #6

              I don't have the data to test with but, I do believe that SUBSTRING works with the TEXT & NTEXT data types. UPDATE noteTable SET note = SUBSTRING(note,0,10000) WHERE DATALENGTH(note) > 10000

              M 1 Reply Last reply
              0
              • M Michael Potter

                I don't have the data to test with but, I do believe that SUBSTRING works with the TEXT & NTEXT data types. UPDATE noteTable SET note = SUBSTRING(note,0,10000) WHERE DATALENGTH(note) > 10000

                M Offline
                M Offline
                Marcus Spitzmiller
                wrote on last edited by
                #7

                Thanks, that works. - Apparently I didn't look hard enough. I guess I didn't realize that substring existed. I tried substr and when that didn't work, I guess I thought that that function didn't exist. Thanks again!

                Marcus Spitzmiller You will never hear me say, "I listen to pretty much everything." That is for people who don't care what goes in their ears.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups