473,434 Members | 1,538 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

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
Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.                     (select name+','+state from [nms_cfg].[dbo].[ATCS_Group] where Group_Address = [WEA])as Wayside
  3.                     ,(SELECT 'G'
  4.                     +SUBSTRING (CONVERT(varchar(100), CAST(WEA AS decimal(38,2))),3, 3 )
  5.                     +'/'
  6.                     + SUBSTRING (CONVERT(varchar(100), CAST(WEA AS decimal(38,2))),6,3 )
  7.                     ) as 'Group ID'
  8.                     ,(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]) )) 
  9.                     + '  ( ' + [base1] + ')' as Base1
  10.                     ,[SSI1]
  11.                     ,(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]) )) 
  12.                     + '  ( ' + [base2] + ')' as Base2
  13.                     ,[SSI2]
  14.                     ,(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]) )) 
  15.                     + '  ( ' + [base3] + ')' as Base3
  16.                     ,[SSI3]          
  17.                     ,cast([Date_Time]as Date) as Date
  18.                     FROM [NMS_RT].[dbo].[RT_Group_Coverage]
  19.                     order by WEA, Date_Time
  20.  
Thanks
Apr 21 '10 #1
1 2214
yarbrough40
320 100+
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?
Apr 22 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
4
by: Robin Tucker | last post by:
Hi, I'm trying to determine with my program whether or not a given database supports a given feature set. To do this I'm querying for certain stored procedures in the sysobjects table and if...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
2
by: Patrick Olurotimi Ige | last post by:
When i run the code below with stored proc :- I get only the first table results :-"templates" even if i fill the dataset with another table for example category,pages etc.. Any ideas? ...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
5
by: mimo | last post by:
Hello, I have seen samples on how to pull data from one table and save back to it using the Form View control. How do I pull from multiple tables and save back to multiple tables on one...
5
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have coded multiple select statements in a single stored procedure, and when I execute this procedure on SQL Server Management Express, I correctly get multiple result sets. But, if I try to add...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.