Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 2nd, 2006, 04:33 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Categorizing SQL Output

Hi All,

         I have a stored procedure which displays list of ADMITTED,QUEUED and DISCHARGED patients. The patient status is stored in a table A represents ADMITTED, Q represents QUEUED and D represents DISCHARGED. I am using a dropdown to display the ADMITTED,QUEUED and DISCHARGED patients. I need to add a new option in the dropdownas ALL which displays all i.e., ADMITTED,QUEUED and DISCHARGED patients but in a classified manner on the same page like:

                            ADMITTED
                            --------
RegNo PatientName Age
---- ----------- ---
A1 PNA 70

                            QUEUED
                            --------
RegNo PatientName Age
---- ----------- ---
D1 PNQ 53

                            DISCHARGED
                            --------
RegNo PatientName Age
---- ----------- ---
Q1 PND 45


How should i code my stored procedure for this kind of formatted output?

Thanks!


 
Old October 8th, 2006, 04:46 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hi Caterpillar,

I think the design is wrong. You need a single table which stores allpatients, with a secondary table that has the Patient Type (Admitted, Queued, Discharged, All). You then have a foreign key reference from the Patient Type table to the Patient table.

Like this:

PatientType Table:
PatientTypeID PatientType Description
------------- ----------- -----------
1 A Admitted
2 Q Queued
3 D Discharged
4 ALL ALL


Patient Table:

PatientID PatientTypeID ReqNo PatientName Age
--------- ------------- ----- ----------- ---
1 1 A1 PNA 70
2 3 D1 PNQ 53

Etc...

That way your stored procedure is very simple. All you need to do is pass the patient type to the stored procedure. For example, if they select QUEUED from the drop down, you pass "Q" to the stored procedure:

CREATE PROCEDURE GetPatientInfo
    @PatientType int
AS
SELECT ReqNo, PatientName, Age
FROM Patient
WHERE PatientType = @PatientType

Now, if this is not an option, then you have to choices. You can create 4 different stored procedures and call the one you want depending on what they select in the drop down. OR, you can create a single procedure with a big IF statement based on what option they select in the drop down (and in this case you'll still need to pass something to to proc).

The way I explained earlier is your best option because it is more normalized.

Hope this helps...


Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
 
Old October 8th, 2006, 04:52 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Oops, I told you incorrectly. You do not pass a "Q" to the proc but ID of the item selected in the drop down (either a 1, 2, 3, or 4), not the specific letter. Make sense?

Sorry about that.

Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 "Using SQL Output Parameters..." burkecrosby BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 22 February 10th, 2010 05:33 PM
SQL Query output to XML using BCP HELP!! miamikk SQL Language 3 May 15th, 2009 08:22 AM
How to write T-SQL to retrieve the required Output anilkumar.dwivedi SQL Language 3 June 26th, 2008 12:37 AM
sql output scandalous ASP.NET 2.0 Basics 15 May 25th, 2007 07:14 AM
SQL output parameters ohiggs SQL Server 2000 4 February 9th, 2004 10:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.