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. selecting maximum entry from sql server compact column

selecting maximum entry from sql server compact column

Scheduled Pinned Locked Moved Database
databasehelpcsharpsql-servervisual-studio
10 Posts 5 Posters 1 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.
  • P Offline
    P Offline
    paul4everyone
    wrote on last edited by
    #1

    please help me, i have been having sleepless nights on this code Select max(convert(int,SubString(Employee_ID,PATINDEX('%[0-9]%',Employee_ID),Len(Employee_ID)))) from Employee this code returns a value of 20, when i used sql server 2012 from a column(varchar()) that contains the following; emp001 emp005 emp020 emp018 but now, in sql server compact 4.0 column(nvarchar()), the following errors are thrown; Error Code: 80040E14 Message : Data conversion failed. [ OLE DB status value (if known) = 2 ] Minor Err.: 26306 Source : SQL Server Compact ADO.NET Data Provider Num. Par. : 2 i am using vb in vs 2012 please what am i not understanding? thanks a lot

    T P L 3 Replies Last reply
    0
    • P paul4everyone

      please help me, i have been having sleepless nights on this code Select max(convert(int,SubString(Employee_ID,PATINDEX('%[0-9]%',Employee_ID),Len(Employee_ID)))) from Employee this code returns a value of 20, when i used sql server 2012 from a column(varchar()) that contains the following; emp001 emp005 emp020 emp018 but now, in sql server compact 4.0 column(nvarchar()), the following errors are thrown; Error Code: 80040E14 Message : Data conversion failed. [ OLE DB status value (if known) = 2 ] Minor Err.: 26306 Source : SQL Server Compact ADO.NET Data Provider Num. Par. : 2 i am using vb in vs 2012 please what am i not understanding? thanks a lot

      T Offline
      T Offline
      Tim Carmichael
      wrote on last edited by
      #2

      Reduce the select statement to its base components, something like 'select max(employee_id) from Employee). Then add in each clause one at a time until it breaks. Understandable, 'select max(employee_id) from Employee' is not what you want, but it may help find the issue. Tim

      P 1 Reply Last reply
      0
      • P paul4everyone

        please help me, i have been having sleepless nights on this code Select max(convert(int,SubString(Employee_ID,PATINDEX('%[0-9]%',Employee_ID),Len(Employee_ID)))) from Employee this code returns a value of 20, when i used sql server 2012 from a column(varchar()) that contains the following; emp001 emp005 emp020 emp018 but now, in sql server compact 4.0 column(nvarchar()), the following errors are thrown; Error Code: 80040E14 Message : Data conversion failed. [ OLE DB status value (if known) = 2 ] Minor Err.: 26306 Source : SQL Server Compact ADO.NET Data Provider Num. Par. : 2 i am using vb in vs 2012 please what am i not understanding? thanks a lot

        P Offline
        P Offline
        paul4everyone
        wrote on last edited by
        #3

        I have found my way :-D out

        1 Reply Last reply
        0
        • P paul4everyone

          please help me, i have been having sleepless nights on this code Select max(convert(int,SubString(Employee_ID,PATINDEX('%[0-9]%',Employee_ID),Len(Employee_ID)))) from Employee this code returns a value of 20, when i used sql server 2012 from a column(varchar()) that contains the following; emp001 emp005 emp020 emp018 but now, in sql server compact 4.0 column(nvarchar()), the following errors are thrown; Error Code: 80040E14 Message : Data conversion failed. [ OLE DB status value (if known) = 2 ] Minor Err.: 26306 Source : SQL Server Compact ADO.NET Data Provider Num. Par. : 2 i am using vb in vs 2012 please what am i not understanding? thanks a lot

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Member 10218952 wrote:

          please what am i not understanding?

          Atomicity. It looks a lot like a formatted field, with a string, and a number that gets padded (for displaying purposes). Each field should hold an atomic value; the example consists of two facts, and should have been split over two fields. That's assuming that "emp" is not a constant.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          P 2 Replies Last reply
          0
          • T Tim Carmichael

            Reduce the select statement to its base components, something like 'select max(employee_id) from Employee). Then add in each clause one at a time until it breaks. Understandable, 'select max(employee_id) from Employee' is not what you want, but it may help find the issue. Tim

            P Offline
            P Offline
            paul4everyone
            wrote on last edited by
            #5

            i found my way out by creating a new column, ID as a int data type, i then used

            Select Max(ID) from Employee

            to get the maximum value. finally i just send a string value of Emp"&ID to Employee_ID Column Thanks for your Reply

            1 Reply Last reply
            0
            • L Lost User

              Member 10218952 wrote:

              please what am i not understanding?

              Atomicity. It looks a lot like a formatted field, with a string, and a number that gets padded (for displaying purposes). Each field should hold an atomic value; the example consists of two facts, and should have been split over two fields. That's assuming that "emp" is not a constant.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              P Offline
              P Offline
              paul4everyone
              wrote on last edited by
              #6

              i found my way out by creating a new column, ID as an int data type, i then used Select Max(ID) from Employee to get the maximum value. finally i just send a string value of Emp"&ID to Employee_ID Column Thanks For your Reply

              M 1 Reply Last reply
              0
              • P paul4everyone

                i found my way out by creating a new column, ID as an int data type, i then used Select Max(ID) from Employee to get the maximum value. finally i just send a string value of Emp"&ID to Employee_ID Column Thanks For your Reply

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

                Which is half of what Eddy suggested, the ID is correct but storing the "Emp" & ID is wrong, this information has no value and is only required in the UI/Reports. It should be created in the output, not stored. This argument goes out the window if you need to maintain backwards compatibility with a crappy design.

                Never underestimate the power of human stupidity RAH

                J 1 Reply Last reply
                0
                • L Lost User

                  Member 10218952 wrote:

                  please what am i not understanding?

                  Atomicity. It looks a lot like a formatted field, with a string, and a number that gets padded (for displaying purposes). Each field should hold an atomic value; the example consists of two facts, and should have been split over two fields. That's assuming that "emp" is not a constant.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  P Offline
                  P Offline
                  paul4everyone
                  wrote on last edited by
                  #8

                  thanks to you all. guess i will learn more about atomicity. life became very much easier when i used

                  Select Max(Employee_ID) from Employee

                  then using substring to trim the output to taste. thanks to you all, i really appreciate it :-D :-D :thumbsup::thumbsup:

                  M 1 Reply Last reply
                  0
                  • P paul4everyone

                    thanks to you all. guess i will learn more about atomicity. life became very much easier when i used

                    Select Max(Employee_ID) from Employee

                    then using substring to trim the output to taste. thanks to you all, i really appreciate it :-D :-D :thumbsup::thumbsup:

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

                    pssst - see the little green up arrow on the right of the message, give Eddy's rep a tickle and up vote the response (the best way to say thanks)

                    Never underestimate the power of human stupidity RAH

                    1 Reply Last reply
                    0
                    • M Mycroft Holmes

                      Which is half of what Eddy suggested, the ID is correct but storing the "Emp" & ID is wrong, this information has no value and is only required in the UI/Reports. It should be created in the output, not stored. This argument goes out the window if you need to maintain backwards compatibility with a crappy design.

                      Never underestimate the power of human stupidity RAH

                      J Offline
                      J Offline
                      Jorgen Andersson
                      wrote on last edited by
                      #10

                      Mycroft Holmes wrote:

                      This argument goes out the window if you need to maintain backwards compatibility with a crappy design.

                      No it doesn't :) You can always keep such stuff in a view, sp or a query. I'm accepting one argument only for keeping a crappy design, and that is: If it's not broken, don't fix it. Ooh, it still feels like Monday to me. :zzz:

                      Be excellent to each other. And... PARTY ON, DUDES! Abraham Lincoln

                      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