Convert a multiple table query to Stored Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • solutionsville
    New Member
    • Feb 2008
    • 4

    Convert a multiple table query to Stored Procedure

    I have a rather complicated query that I need to convert to a Stored Procedure so that I can more easily call this query in an asp.net page.

    The idea is to have two calander controls on the web page, and textbox/button.

    Enter the name of the location and select the date range from the calander. Click the button and display the results in a GridView.

    Paramaters needed are Name, StartDate and EndDate.

    Here is the query
    Code:
    SELECT
                        (select name+','+state from [nms_cfg].[dbo].[ATCS_Group] where Group_Address = [WEA])as Wayside
                        ,(SELECT 'G'
                        +SUBSTRING (CONVERT(varchar(100), CAST(WEA AS decimal(38,2))),3, 3 )
                        +'/'
                        + SUBSTRING (CONVERT(varchar(100), CAST(WEA AS decimal(38,2))),6,3 )
                        ) as 'Group ID'
                        ,(SELECT [Name]+','+[State] FROM [NMS_CFG].[dbo].[Base_Equipment] where Base_Equip_Address= (select top 1 Base_Equip_Address from [NMS_CFG].[dbo].[be_xref_oa] where x_pbase = master.dbo.ufnStringToPbase([base1]) )) 
                        + '  ( ' + [base1] + ')' as Base1
                        ,[SSI1]
                        ,(SELECT [Name]+','+[State] FROM [NMS_CFG].[dbo].[Base_Equipment] where Base_Equip_Address= (select top 1 Base_Equip_Address from [NMS_CFG].[dbo].[be_xref_oa] where x_pbase = master.dbo.ufnStringToPbase([base2]) )) 
                        + '  ( ' + [base2] + ')' as Base2
                        ,[SSI2]
                        ,(SELECT [Name]+','+[State] FROM [NMS_CFG].[dbo].[Base_Equipment] where Base_Equip_Address= (select top 1 Base_Equip_Address from [NMS_CFG].[dbo].[be_xref_oa] where x_pbase = master.dbo.ufnStringToPbase([base3]) )) 
                        + '  ( ' + [base3] + ')' as Base3
                        ,[SSI3]          
                        ,cast([Date_Time]as Date) as Date
                        FROM [NMS_RT].[dbo].[RT_Group_Coverage]
                        order by WEA, Date_Time
    Thanks
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2
    you failed to actually ask a question... are you wondering about the syntax of creating a stored procedure? or are you curious on how to create and apply @variables? are you stuck on how to call a procedure from a .net app?

    Comment

    Working...