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. INLINE FUNCTION

INLINE FUNCTION

Scheduled Pinned Locked Moved Database
help
16 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.
  • I Offline
    I Offline
    It_tech
    wrote on last edited by
    #1

    Hi all, I have a problem in getting the one below to work. I think i have used the right syntax. But keeps coming with error on EXEC Lline... CREATE FUNCTION Summary (@Month varchar(30),@Year varchar(30),@ShowType varchar(30)) RETURNS TABLE AS RETURN With EXECUTE C_WEB_sp_RevenueSummaryByShow 'April', '2010', '3' Go Thansk for your time

    J 1 Reply Last reply
    0
    • I It_tech

      Hi all, I have a problem in getting the one below to work. I think i have used the right syntax. But keeps coming with error on EXEC Lline... CREATE FUNCTION Summary (@Month varchar(30),@Year varchar(30),@ShowType varchar(30)) RETURNS TABLE AS RETURN With EXECUTE C_WEB_sp_RevenueSummaryByShow 'April', '2010', '3' Go Thansk for your time

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      It_tech wrote:

      But keeps coming with error on EXEC Lline...

      Do you think the error message might help us debug your problem?

      I 1 Reply Last reply
      0
      • J J4amieC

        It_tech wrote:

        But keeps coming with error on EXEC Lline...

        Do you think the error message might help us debug your problem?

        I Offline
        I Offline
        It_tech
        wrote on last edited by
        #3

        Many thanks for your help. Here is the error message: Msg 156, Level 15, State 1, Procedure Summary, Line 6 Incorrect syntax near the keyword 'EXECUTE'.

        J 1 Reply Last reply
        0
        • I It_tech

          Many thanks for your help. Here is the error message: Msg 156, Level 15, State 1, Procedure Summary, Line 6 Incorrect syntax near the keyword 'EXECUTE'.

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          The error message is somewhat descriptive. The main problem you're having is that you wont be able to return the result of a stored procedure call from a function. Its just not possible in SQLServer.

          I 1 Reply Last reply
          0
          • J J4amieC

            The error message is somewhat descriptive. The main problem you're having is that you wont be able to return the result of a stored procedure call from a function. Its just not possible in SQLServer.

            I Offline
            I Offline
            It_tech
            wrote on last edited by
            #5

            Thanks Once again.Its Much appreciated.What is it about extended Stored Procedures?I hope we can execute them in table valued functions.

            J 1 Reply Last reply
            0
            • I It_tech

              Thanks Once again.Its Much appreciated.What is it about extended Stored Procedures?I hope we can execute them in table valued functions.

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6

              As far as I know, you cant execute any SP's in a Function.

              I 1 Reply Last reply
              0
              • J J4amieC

                As far as I know, you cant execute any SP's in a Function.

                I Offline
                I Offline
                It_tech
                wrote on last edited by
                #7

                Thanks.What is the way around then?

                M J 2 Replies Last reply
                0
                • I It_tech

                  Thanks.What is the way around then?

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

                  Don't use a function!

                  Never underestimate the power of human stupidity RAH

                  1 Reply Last reply
                  0
                  • I It_tech

                    Thanks.What is the way around then?

                    J Offline
                    J Offline
                    J4amieC
                    wrote on last edited by
                    #9

                    Without knowing what you're trying to achieve, I cant answer that.

                    I 1 Reply Last reply
                    0
                    • J J4amieC

                      Without knowing what you're trying to achieve, I cant answer that.

                      I Offline
                      I Offline
                      It_tech
                      wrote on last edited by
                      #10

                      Hi There, I tried changing it to a Stored procedure but still have a problem ALTER PROCEDURE [dbo].[sp_LiveRevenueGraph] -- Add the parameters for the stored procedure here @ShowType NVARCHAR(20), @Statistic NVARCHAR(20) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @data TABLE ([Week] NVARCHAR(120), Sunday DECIMAL(12,5), Monday DECIMAL(12,5), Tuesday DECIMAL(12,5), Wednesday DECIMAL(12,5), Thursday DECIMAL(12,5), Friday DECIMAL(12,5), Saturday DECIMAL(12,5), SubTotal DECIMAL(12,5)) -- Insert statements for procedure here -- INSERT INTO @data EXECUTE C_WEB_sp_RevenueAchievedByShow 0, @ShowType; END Error : --INSERT EXEC statement cannot be nested Please advice. Thanks

                      J 1 Reply Last reply
                      0
                      • I It_tech

                        Hi There, I tried changing it to a Stored procedure but still have a problem ALTER PROCEDURE [dbo].[sp_LiveRevenueGraph] -- Add the parameters for the stored procedure here @ShowType NVARCHAR(20), @Statistic NVARCHAR(20) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @data TABLE ([Week] NVARCHAR(120), Sunday DECIMAL(12,5), Monday DECIMAL(12,5), Tuesday DECIMAL(12,5), Wednesday DECIMAL(12,5), Thursday DECIMAL(12,5), Friday DECIMAL(12,5), Saturday DECIMAL(12,5), SubTotal DECIMAL(12,5)) -- Insert statements for procedure here -- INSERT INTO @data EXECUTE C_WEB_sp_RevenueAchievedByShow 0, @ShowType; END Error : --INSERT EXEC statement cannot be nested Please advice. Thanks

                        J Offline
                        J Offline
                        J4amieC
                        wrote on last edited by
                        #11

                        This is the answer you're looking for: http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure[^] Google is your friend for this sort of question. Learn to use it.

                        I 1 Reply Last reply
                        0
                        • J J4amieC

                          This is the answer you're looking for: http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure[^] Google is your friend for this sort of question. Learn to use it.

                          I Offline
                          I Offline
                          It_tech
                          wrote on last edited by
                          #12

                          Thanks very much for your help. I have changed it to the following But seems to have problem with My server Name when using Open Query Declare @ServName nvarchar(50) set @ServName= (select @@SERVERNAME) select @ServName SELECT * INTO #data FROM OPENQUERY(@ServName, 'EXEc C_WEB_sp_RevenueAchievedByShow 0, @ShowType') Error : Msg 102, Level 15, State 1, Procedure sp_LiveRevenueGraph, Line 22 Incorrect syntax near '@ServName

                          J L 2 Replies Last reply
                          0
                          • I It_tech

                            Thanks very much for your help. I have changed it to the following But seems to have problem with My server Name when using Open Query Declare @ServName nvarchar(50) set @ServName= (select @@SERVERNAME) select @ServName SELECT * INTO #data FROM OPENQUERY(@ServName, 'EXEc C_WEB_sp_RevenueAchievedByShow 0, @ShowType') Error : Msg 102, Level 15, State 1, Procedure sp_LiveRevenueGraph, Line 22 Incorrect syntax near '@ServName

                            J Offline
                            J Offline
                            J4amieC
                            wrote on last edited by
                            #13

                            There is no possible way for me to debug that. I have no access to your database, no knowledge of what you're doing. I think you need to spend some time debugging your problem yourself.

                            1 Reply Last reply
                            0
                            • I It_tech

                              Thanks very much for your help. I have changed it to the following But seems to have problem with My server Name when using Open Query Declare @ServName nvarchar(50) set @ServName= (select @@SERVERNAME) select @ServName SELECT * INTO #data FROM OPENQUERY(@ServName, 'EXEc C_WEB_sp_RevenueAchievedByShow 0, @ShowType') Error : Msg 102, Level 15, State 1, Procedure sp_LiveRevenueGraph, Line 22 Incorrect syntax near '@ServName

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

                              Hi, Just tried it, the code below works for me on the AdventureWorks database;

                              sp_configure 'Show Advanced Options', 1
                              GO
                              RECONFIGURE
                              GO
                              sp_configure 'Ad Hoc Distributed Queries', 1
                              GO
                              RECONFIGURE
                              GO

                              SELECT *
                              INTO #MyTempTable
                              FROM OPENROWSET(
                              'SQLNCLI',
                              'Server=(local);Trusted_Connection=yes;',
                              'EXEC AdventureWorks.dbo.uspGetEmployeeManagers 1'
                              )

                              Hope this helps :)

                              I are Troll :suss:

                              I 1 Reply Last reply
                              0
                              • L Lost User

                                Hi, Just tried it, the code below works for me on the AdventureWorks database;

                                sp_configure 'Show Advanced Options', 1
                                GO
                                RECONFIGURE
                                GO
                                sp_configure 'Ad Hoc Distributed Queries', 1
                                GO
                                RECONFIGURE
                                GO

                                SELECT *
                                INTO #MyTempTable
                                FROM OPENROWSET(
                                'SQLNCLI',
                                'Server=(local);Trusted_Connection=yes;',
                                'EXEC AdventureWorks.dbo.uspGetEmployeeManagers 1'
                                )

                                Hope this helps :)

                                I are Troll :suss:

                                I Offline
                                I Offline
                                It_tech
                                wrote on last edited by
                                #15

                                Many thanks for your help. I have the following Error : Msg 7403, Level 16, State 1, Line 2 The OLE DB provider "PC-NAME\SqlDev" has not been registered. Here is how i changed it on my Development : sp_configure 'Show Advanced Options', 1 GO RECONFIGURE GO sp_configure 'Ad Hoc Distributed Queries', 1 GO RECONFIGURE GO SELECT * INTO #MyTempTable FROM OPENROWSET( 'Kibrom\SqlDev', 'Server=(local);Trusted_Connection=yes;', 'Exec [dbo].[C_WEB_sp_RevenueAchievedByShow] 1,2' )

                                L 1 Reply Last reply
                                0
                                • I It_tech

                                  Many thanks for your help. I have the following Error : Msg 7403, Level 16, State 1, Line 2 The OLE DB provider "PC-NAME\SqlDev" has not been registered. Here is how i changed it on my Development : sp_configure 'Show Advanced Options', 1 GO RECONFIGURE GO sp_configure 'Ad Hoc Distributed Queries', 1 GO RECONFIGURE GO SELECT * INTO #MyTempTable FROM OPENROWSET( 'Kibrom\SqlDev', 'Server=(local);Trusted_Connection=yes;', 'Exec [dbo].[C_WEB_sp_RevenueAchievedByShow] 1,2' )

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

                                  Nice :) --edit The first argument should be a provider; the name of the server has already been provided as "(local)" - this gets replaced with "Kibrom\SqlDev". Something like below should work;

                                  SELECT *
                                  INTO #MyTempTable
                                  FROM OPENROWSET(
                                  'SQLNCLI',
                                  'Server=(local);Trusted_Connection=yes;',
                                  'Exec [dbo].[C_WEB_sp_RevenueAchievedByShow] 1,2'
                                  )

                                  I are Troll :suss:

                                  modified on Friday, June 4, 2010 2:35 PM

                                  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