How can I convert this sql query to a stored procedure?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akocjello
    New Member
    • Jan 2013
    • 5

    How can I convert this sql query to a stored procedure?

    Code:
    SELECT DISTINCT  broker,
    COUNT(case when cntsze=20 then cntsze end) as '20',
    COUNT(case when cntsze=40 then cntsze end) as '40',
    COUNT(case when cntsze=45 then cntsze end) as '45' 
    FROM CYMgps
    WHERE ( sysdte BETWEEN '2012-11-01 00:00:00' and '2012-11-30 23:59:59')
    GROUP BY  broker
    ORDER BY broker asc
    Last edited by NeoPa; Jan 11 '13, 01:24 PM. Reason: Tidied.
  • Uncle Dickie
    New Member
    • Nov 2008
    • 67

    #2
    Start it with:

    Code:
    USE <database>
    GO
    CREATE PROCEDURE <procedure_name> AS
    
    -- your query here
    If you need to edit it in future:
    Code:
    ALTER PROCEDURE <procedure_name> AS

    Comment

    • ravikumarr
      New Member
      • Jan 2013
      • 6

      #3
      hi akocjello,
      create the procedure like below.
      create procedure procedurename
      as
      begin
      //write the query u want to perform
      // e.g select * from tablename
      end


      then

      execute procedure procedurename

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32636

        #4
        When you choose to create or add a new Stored Procedure all these heading and trailing bits are inserted for you. You simply need to fill in the name etc. and the SQL and save it. It's hard to imagine why you would need to ask such a question unless you hadn't even looked at it for yourself first.

        Comment

        • ravikumarr
          New Member
          • Jan 2013
          • 6

          #5
          how to pass the immediate values to load event

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32636

            #6
            What do you mean by "load event"? I know of no such concept.

            I can guess you mean literal when you say "immediate", but I'm still left with no idea what your question means.

            Comment

            • akocjello
              New Member
              • Jan 2013
              • 5

              #7
              thanks for the reply

              NeoPa i looked it for my self but when i tried to do it i always encountered an error... but now it works :)
              can i ask another question?
              Last edited by NeoPa; Jan 13 '13, 11:58 PM. Reason: Removed extra question (Hijack).

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32636

                #8
                You certainly may ask a new question, but just as certainly not in this thread.

                Each question must be asked in a separate thread of course, but the question you want to ask should also be asked in a different forum. You won't find that many VB.NET experts that frequent this (SQL) forum ;-)

                Comment

                • akocjello
                  New Member
                  • Jan 2013
                  • 5

                  #9
                  Sorry NeoPa im new in this forum and i dont know that... thanks for telling me

                  sorry again :)

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32636

                    #10
                    No need to worry at this stage. I can see you are new and nothing you've done yet has been a problem.

                    Comment

                    • akocjello
                      New Member
                      • Jan 2013
                      • 5

                      #11
                      thank you for all the reply :)
                      i made it. now my program is 90% done :)


                      thanks again :)

                      Comment

                      Working...