-
SQL Server - Conditional Group By? Need Help PLS!
I am creating stored procedure in SQL Server 2008. I'm a little confused on how to group a specific column only when it meets the criteria below. Can anyone help? I have notes in the code below. Thanks.
Criteria:
1) @Coverage & @GroupByMain are optional i.e if a null value is passed for these parameters, they must be ignored
2) If @GroupByMain is not null then the column CalculatedSDCash should be grouped by HiNetMajor
------------------------------------------------------------------
CREATE PROCEDURE [dbo].[Sel_DCF_AcctCurrStatusHistory]
@AsOfDate datetime,
@Coverage nvarchar(20),
@GroupByMain nvarchar(4) --Will either be 'MAIN' or NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM tblDCF_AcctCurrStatusHistory
WHERE ((@Coverage IS NULL) OR (Coverage = @Coverage))-- AND
--((@GroupByMain IS NULL) OR (@GroupByMain IS NOT NULL AND **Don't know what to do here** ))
GROUP BY
--Not sure how I group "CalculatedSDCash" by "HiNetMajor" only if "GroupByMain" is not null??? And do I sum "CalculatedSDCash"?
END
Similar Threads
-
By rperez in forum Database
Replies: 5
Last Post: 01-02-2009, 04:14 PM
-
By imranx101 in forum .NET
Replies: 10
Last Post: 06-13-2008, 11:32 AM
-
By Dan Staggs in forum Careers
Replies: 0
Last Post: 08-07-2002, 11:04 AM
-
By Aditya in forum Database
Replies: 0
Last Post: 04-29-2002, 07:39 AM
-
By Marie in forum Database
Replies: 0
Last Post: 11-20-2000, 05:37 AM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|