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. Problem with Execute query by EXEC(@string)

Problem with Execute query by EXEC(@string)

Scheduled Pinned Locked Moved Database
databasehelpsharepoint
13 Posts 6 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.
  • N Offline
    N Offline
    nainakarri
    wrote on last edited by
    #1

    Hi I have written a stored procedure where i am taking the select query into a variable @string and executing the query. i am generating the query dynamically based on the SP inputs. If the query is below 4000 chars , there is no prob with it. If it exceeds then query is not executing. Kindly help.... Thanks in advance Naina

    Naina

    C S N 3 Replies Last reply
    0
    • N nainakarri

      Hi I have written a stored procedure where i am taking the select query into a variable @string and executing the query. i am generating the query dynamically based on the SP inputs. If the query is below 4000 chars , there is no prob with it. If it exceeds then query is not executing. Kindly help.... Thanks in advance Naina

      Naina

      C Offline
      C Offline
      Covean
      wrote on last edited by
      #2

      If I'm right you will not be able to query/search for data/text that is larger than 4000 chars. All column types above text(4000), like NVarChar(max) can't be a query parameter. I hope somebody can confirm that. Greetings Covean

      N 1 Reply Last reply
      0
      • C Covean

        If I'm right you will not be able to query/search for data/text that is larger than 4000 chars. All column types above text(4000), like NVarChar(max) can't be a query parameter. I hope somebody can confirm that. Greetings Covean

        N Offline
        N Offline
        nainakarri
        wrote on last edited by
        #3

        Hi thanks for the reply..... just did a small change by declaring as varchar(MAX) and its accepting more than 4000. Thank you Regards Naina

        Naina

        C M 2 Replies Last reply
        0
        • N nainakarri

          Hi thanks for the reply..... just did a small change by declaring as varchar(MAX) and its accepting more than 4000. Thank you Regards Naina

          Naina

          C Offline
          C Offline
          Covean
          wrote on last edited by
          #4

          No problem and thank you for confirming that I'm wrong. And good to know.   :laugh: Greetings Covean

          1 Reply Last reply
          0
          • N nainakarri

            Hi thanks for the reply..... just did a small change by declaring as varchar(MAX) and its accepting more than 4000. Thank you Regards Naina

            Naina

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            You may be limited to 8000 character, the max of varchar, not sure if varchar(max) overcomes this limitation.

            Never underestimate the power of human stupidity RAH

            N 1 Reply Last reply
            0
            • M Mycroft Holmes

              You may be limited to 8000 character, the max of varchar, not sure if varchar(max) overcomes this limitation.

              Never underestimate the power of human stupidity RAH

              N Offline
              N Offline
              nainakarri
              wrote on last edited by
              #6

              if i give nvarchar(8000) it says that i have crosses the linit of 4000 characters. i am using sqlserver 2005. and now i noticed that varchar(MAX) is taking only 4000 characters. Regards Naina

              Naina

              M 1 Reply Last reply
              0
              • N nainakarri

                if i give nvarchar(8000) it says that i have crosses the linit of 4000 characters. i am using sqlserver 2005. and now i noticed that varchar(MAX) is taking only 4000 characters. Regards Naina

                Naina

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #7

                use varchar(8000)

                Never underestimate the power of human stupidity RAH

                N 1 Reply Last reply
                0
                • M Mycroft Holmes

                  use varchar(8000)

                  Never underestimate the power of human stupidity RAH

                  N Offline
                  N Offline
                  nainakarri
                  wrote on last edited by
                  #8

                  i declared as varchar(8000) and assigned a query to it. but when i tried to print the length and string, it shows only till 4000 chars and the length also its showing only 4000. :( Regards Naina

                  Naina

                  1 Reply Last reply
                  0
                  • N nainakarri

                    Hi I have written a stored procedure where i am taking the select query into a variable @string and executing the query. i am generating the query dynamically based on the SP inputs. If the query is below 4000 chars , there is no prob with it. If it exceeds then query is not executing. Kindly help.... Thanks in advance Naina

                    Naina

                    S Offline
                    S Offline
                    soni uma
                    wrote on last edited by
                    #9

                    Hi use nvarchar(8000) umesh

                    N 1 Reply Last reply
                    0
                    • S soni uma

                      Hi use nvarchar(8000) umesh

                      N Offline
                      N Offline
                      nainakarri
                      wrote on last edited by
                      #10

                      The size (8000) given to the parameter '@sql' exceeds the maximum allowed (4000). is the error if i use nvarchar(8000) :( Regards Naina

                      Naina

                      A 1 Reply Last reply
                      0
                      • N nainakarri

                        The size (8000) given to the parameter '@sql' exceeds the maximum allowed (4000). is the error if i use nvarchar(8000) :( Regards Naina

                        Naina

                        A Offline
                        A Offline
                        Abhishek Sur
                        wrote on last edited by
                        #11

                        Yes... Hightest value of NVARCHAR is 4000 and VARCHAR is 8000 BUT NVARCHAR takes large CHARSET.. So use NVARCHAR only when you need. :)

                        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                        My Latest Articles-->** Microsoft Bing MAP using Javascript
                        CLR objects in SQL Server 2005
                        Uncommon C# Keywords
                        /xml>

                        N 1 Reply Last reply
                        0
                        • A Abhishek Sur

                          Yes... Hightest value of NVARCHAR is 4000 and VARCHAR is 8000 BUT NVARCHAR takes large CHARSET.. So use NVARCHAR only when you need. :)

                          Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                          My Latest Articles-->** Microsoft Bing MAP using Javascript
                          CLR objects in SQL Server 2005
                          Uncommon C# Keywords
                          /xml>

                          N Offline
                          N Offline
                          nainakarri
                          wrote on last edited by
                          #12

                          I finally got the answere..... :) I declared @string as varchar(8000). But there are nvarchars declared which i am assigning to @string which finally lead to the problem . because of this @string is taking only 4000 charecters, I replaced all nvarchars with varchars and finally its taking morethan 4000 charecters. Regards Naina

                          Naina

                          1 Reply Last reply
                          0
                          • N nainakarri

                            Hi I have written a stored procedure where i am taking the select query into a variable @string and executing the query. i am generating the query dynamically based on the SP inputs. If the query is below 4000 chars , there is no prob with it. If it exceeds then query is not executing. Kindly help.... Thanks in advance Naina

                            Naina

                            N Offline
                            N Offline
                            NIRMAL UPADHYAY
                            wrote on last edited by
                            #13

                            Take @string as varchar(max) and then try executing it Hope it helps!

                            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