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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Please Help Me

Please Help Me

Scheduled Pinned Locked Moved Database
designhelp
7 Posts 3 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
    Mkanchha
    wrote on last edited by
    #1

    Hi to all, I want to write storedprocedure which take Name or Year as Parameter and Display Records Order by Name or Year. Note:From UI User may select Orderby Name or Year. Mkanchha

    C A 3 Replies Last reply
    0
    • M Mkanchha

      Hi to all, I want to write storedprocedure which take Name or Year as Parameter and Display Records Order by Name or Year. Note:From UI User may select Orderby Name or Year. Mkanchha

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      We can't write this for you because we don't know what your database schema is. If this is the only two orders you may want, I'd write a proc for each, otherwise I believe you need to build your SQL as a string and execute it.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • M Mkanchha

        Hi to all, I want to write storedprocedure which take Name or Year as Parameter and Display Records Order by Name or Year. Note:From UI User may select Orderby Name or Year. Mkanchha

        A Offline
        A Offline
        Arun Immanuel
        wrote on last edited by
        #3

        Pass "1" or "2" to the database and using simple if statement sort accordingly.

        Regards, Arun Kumar.A

        1 Reply Last reply
        0
        • M Mkanchha

          Hi to all, I want to write storedprocedure which take Name or Year as Parameter and Display Records Order by Name or Year. Note:From UI User may select Orderby Name or Year. Mkanchha

          A Offline
          A Offline
          Arun Immanuel
          wrote on last edited by
          #4

          Or try this: select * from tblName order by case WHEN @parmaeter=1 then Name else Year end ASC

          Regards, Arun Kumar.A

          M 1 Reply Last reply
          0
          • A Arun Immanuel

            Or try this: select * from tblName order by case WHEN @parmaeter=1 then Name else Year end ASC

            Regards, Arun Kumar.A

            M Offline
            M Offline
            Mkanchha
            wrote on last edited by
            #5

            Thanks for your Replay. I get the SP it's comple successfully but while execute it giving the error. THIS IS MY sp ----------------- ALTER proc Test (@iOrder char(1)) as select * from tblabc order by case WHEN @iOrder='1' then vsName else nYOP end ASC -------------- EXEC TEST '1' -------------------- Error: Msg 8114, Level 16, State 5, Procedure Test, Line 4 Error converting data type varchar to numeric. ------------------------------------------------------ Please Tellme where I made Mistake Mkanchha

            A 1 Reply Last reply
            0
            • M Mkanchha

              Thanks for your Replay. I get the SP it's comple successfully but while execute it giving the error. THIS IS MY sp ----------------- ALTER proc Test (@iOrder char(1)) as select * from tblabc order by case WHEN @iOrder='1' then vsName else nYOP end ASC -------------- EXEC TEST '1' -------------------- Error: Msg 8114, Level 16, State 5, Procedure Test, Line 4 Error converting data type varchar to numeric. ------------------------------------------------------ Please Tellme where I made Mistake Mkanchha

              A Offline
              A Offline
              Arun Immanuel
              wrote on last edited by
              #6

              Sorry , I have forgotten to tell you that the above statement will work only if both the columns have same datatype. try this: select * from tabeName order by case when @a=1 then col1 end, case when @a=2 then col2 end Hope, this helps you.

              Regards, Arun Kumar.A

              M 1 Reply Last reply
              0
              • A Arun Immanuel

                Sorry , I have forgotten to tell you that the above statement will work only if both the columns have same datatype. try this: select * from tabeName order by case when @a=1 then col1 end, case when @a=2 then col2 end Hope, this helps you.

                Regards, Arun Kumar.A

                M Offline
                M Offline
                Mkanchha
                wrote on last edited by
                #7

                Thanks, Now it's working Perfect MKanchha

                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