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. help me to write procedure

help me to write procedure

Scheduled Pinned Locked Moved Database
sharepointhelp
12 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.
  • A amistry_petlad

    Hi all, I wanna write 2 procedure 1) is when I execute it with parameter its give me the records of that particular table e.g. EXEC sp_Showrecords tablename 2) is when I execute it shown be all tables when I enter datbase name as parameter e.g EXEC sp_ShowTableaList dbname Can anybody help me.

    N Offline
    N Offline
    nelsonpaixao
    wrote on last edited by
    #2

    hi, i don´t understand want you want:confused: Maybe i can help you there What kind of database you have and what do you want your procedure to do? :confused: Didn´t you found anything here in codeproject? Do you want do match/join contents from diferent tables and display it? try inner join in search code project.

    A 1 Reply Last reply
    0
    • N nelsonpaixao

      hi, i don´t understand want you want:confused: Maybe i can help you there What kind of database you have and what do you want your procedure to do? :confused: Didn´t you found anything here in codeproject? Do you want do match/join contents from diferent tables and display it? try inner join in search code project.

      A Offline
      A Offline
      amistry_petlad
      wrote on last edited by
      #3

      I am using SQL server. e.g. Create procedure sp_Fetchrecords @tbname sysname=NULL AS Select * from @tbname go gives me error

      N L 2 Replies Last reply
      0
      • A amistry_petlad

        I am using SQL server. e.g. Create procedure sp_Fetchrecords @tbname sysname=NULL AS Select * from @tbname go gives me error

        N Offline
        N Offline
        nelsonpaixao
        wrote on last edited by
        #4

        check the store procedures folder if it is already there! use alter procedure to change it. i usualy set the database on which i write on sql server up-left corner combobox. i don´t not use code but you can do that, do you need to code that? create procedures like this (with inner join) --------------sp----------- create procedure vendas_criadas @data_ini as smalldatetime, @data_fim as smalldatetime as begin select ve.id_venda as 'ID Venda',al.nome as 'Album',cl.primeiro_nome+' '+cl.ultimo_nome as 'Cliente',ut1.primeiro_nome+' '+ut1.ultimo_nome as 'Criador',ve.id_utilizador_criador_data as 'Data Criação' from dbo.vendas as ve inner join dbo.albuns as al on ve.id_album = al.id_album inner join dbo.clientes as cl on ve.id_cliente = cl.id_cliente inner join dbo.SPY_utilizadores as ut1 on ve.id_utilizador_criador = ut1.id_utilizador where ve.data_registo between @data_ini and @data_fim end go -------------execute------------------- exec vendas_criadas @data_ini = '1/1/2007', @data_fim = '1/1/2008'

        A 1 Reply Last reply
        0
        • N nelsonpaixao

          check the store procedures folder if it is already there! use alter procedure to change it. i usualy set the database on which i write on sql server up-left corner combobox. i don´t not use code but you can do that, do you need to code that? create procedures like this (with inner join) --------------sp----------- create procedure vendas_criadas @data_ini as smalldatetime, @data_fim as smalldatetime as begin select ve.id_venda as 'ID Venda',al.nome as 'Album',cl.primeiro_nome+' '+cl.ultimo_nome as 'Cliente',ut1.primeiro_nome+' '+ut1.ultimo_nome as 'Criador',ve.id_utilizador_criador_data as 'Data Criação' from dbo.vendas as ve inner join dbo.albuns as al on ve.id_album = al.id_album inner join dbo.clientes as cl on ve.id_cliente = cl.id_cliente inner join dbo.SPY_utilizadores as ut1 on ve.id_utilizador_criador = ut1.id_utilizador where ve.data_registo between @data_ini and @data_fim end go -------------execute------------------- exec vendas_criadas @data_ini = '1/1/2007', @data_fim = '1/1/2008'

          A Offline
          A Offline
          amistry_petlad
          wrote on last edited by
          #5

          this answer is not related with my question . like simple select * statement inside procedure I didn't get your answer

          1 Reply Last reply
          0
          • A amistry_petlad

            Hi all, I wanna write 2 procedure 1) is when I execute it with parameter its give me the records of that particular table e.g. EXEC sp_Showrecords tablename 2) is when I execute it shown be all tables when I enter datbase name as parameter e.g EXEC sp_ShowTableaList dbname Can anybody help me.

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

            Sorry if i can´t help you there, i sure more advanced programmer will help. Good luck

            A 1 Reply Last reply
            0
            • A amistry_petlad

              I am using SQL server. e.g. Create procedure sp_Fetchrecords @tbname sysname=NULL AS Select * from @tbname go gives me error

              L Offline
              L Offline
              leoinfo
              wrote on last edited by
              #7

              Create procedure sp_Fetchrecords
              @tbname sysname=NULL
              AS
              SET NOCOUNT ON
              IF @tbname IS NOT NULL
              BEGIN
              DECLARE @cmd NVARCHAR(4000)
              SET @cmd = 'Select * from '+@tbname
              EXEC(@cmd)
              END
              go

              A 1 Reply Last reply
              0
              • L leoinfo

                Create procedure sp_Fetchrecords
                @tbname sysname=NULL
                AS
                SET NOCOUNT ON
                IF @tbname IS NOT NULL
                BEGIN
                DECLARE @cmd NVARCHAR(4000)
                SET @cmd = 'Select * from '+@tbname
                EXEC(@cmd)
                END
                go

                A Offline
                A Offline
                amistry_petlad
                wrote on last edited by
                #8

                thanks can you explain me why we have to execute the set command in procedure and one more question what is dynamic procedure and why should we have to use it. many thanks for your help:rose:

                P 1 Reply Last reply
                0
                • N nelsonpaixao

                  Sorry if i can´t help you there, i sure more advanced programmer will help. Good luck

                  A Offline
                  A Offline
                  amistry_petlad
                  wrote on last edited by
                  #9

                  thanks :rose:

                  1 Reply Last reply
                  0
                  • A amistry_petlad

                    thanks can you explain me why we have to execute the set command in procedure and one more question what is dynamic procedure and why should we have to use it. many thanks for your help:rose:

                    P Offline
                    P Offline
                    Paul Conrad
                    wrote on last edited by
                    #10

                    amistry_petlad wrote:

                    explain me why we have to execute the set command in procedure

                    Here is an explanation for SET NOCOUNT ON[^].....

                    "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                    A 1 Reply Last reply
                    0
                    • P Paul Conrad

                      amistry_petlad wrote:

                      explain me why we have to execute the set command in procedure

                      Here is an explanation for SET NOCOUNT ON[^].....

                      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                      A Offline
                      A Offline
                      amistry_petlad
                      wrote on last edited by
                      #11

                      nO SORRY set is for SET @cmd

                      P 1 Reply Last reply
                      0
                      • A amistry_petlad

                        nO SORRY set is for SET @cmd

                        P Offline
                        P Offline
                        Paul Conrad
                        wrote on last edited by
                        #12

                        :-O I just realized there was the second one. The second one sets a variable that is the sql string, and the exec(...) executes the sql string. You could get really fancy with this stored proc, such as adding where clause, and order by as parameters into the stored proc, and add them to the @cmd variable.

                        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                        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