Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help in multiple oreder by

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2011-10-20 : 05:53:59
I have a requirement for ordering my result set on the bases of input
From some boolean parameter i wanted to decide which column should add in oreder by or not.
those are boolean parameters

following is my stpred procedure query


SELECT csm.fkJobID,
csm.csmContainerID,
csm.fkSegmentID,
csm.csmContainerType,
csm.csmContainerLevel,
csm.csmDisplayContainerID,
csm.csmContainerDestinationZip,
csm.csmContainerGroupingDescription,
csm.csmEntryPointActualOrDeliveryLocaleKey,
csmEntryPointforEntryDiscountFacilityType,
csmActualinductionDate,
csmActualInductionTime,
csmScheduledInductionDate,
csmScheduledInductionTime,
csmScheduledInHomeDate,
csm.csmParentContainerReferenceID
FROM ContainerSummaryRecord csm
WHERE ( csm.fkJobID = @fkMAJobID )
AND ( csm.csmIsDeleted = 0 )
AND csmContainerType IN ( 'O', 'T', 'E', 'F',
'S', '1', '2', '3' )
AND ( csmParentContainerReferenceID IS NULL
OR csmParentContainerReferenceID = '' )
AND ( csm.csmCSMRecordStatus NOT LIKE 'D' )
ORDER BY ( CASE
WHEN( @ContainerDestinationZip = 1 ) THEN csm.csmContainerDestinationZip
END ),
( CASE
WHEN( @LocaleKey = 1 ) THEN csm.csmEntryPointActualOrDeliveryLocaleKey
END ),
( CASE
WHEN( @InHomeDate = 1 ) THEN csm.csmScheduledInHomeDate
END ),
( CASE
WHEN( @InductionDate = 1 ) THEN csm.csmScheduledInductionDate
END ),
( CASE
WHEN( @InductionTime = 1 ) THEN csm.csmScheduledInductionTime
END ),
( CASE
WHEN( @FacilityType = 1 ) THEN csm.csmEntryPointforEntryDiscountFacilityType
END ),
( CASE
WHEN( @SortLevel = 1 ) THEN csm.csmContainerLevel
END ),
( CASE
WHEN( @CGD = 1 ) THEN csm.csmContainerGroupingDescription
END );



Kamran Shahid
Sr. Software Engineer
(MCSD.Net,MCPD.net)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-20 : 05:57:33
isnt this enough?

ORDER BY CASE
WHEN( @ContainerDestinationZip = 1 ) THEN csm.csmContainerDestinationZip
WHEN( @LocaleKey = 1 ) THEN csm.csmEntryPointActualOrDeliveryLocaleKey

WHEN( @InHomeDate = 1 ) THEN csm.csmScheduledInHomeDate
...
END



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2011-10-20 : 06:25:24
ok

Kamran Shahid
Sr. Software Engineer
(MCSD.Net,MCPD.net)

Go to Top of Page
   

- Advertisement -