Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
select *
from table
where (@SortOrder=1 and Col1='Value') or (@SortOrder=2 and Col3='test') or (@SortOrder=3 and Col7='Test2') or (@SortOrder=4 and Col4 = 'SomethingElse')
Declare @Temp Table (Id Integer, Name VarChar(20))
Insert Into @Temp Values(1, 'George')
Insert Into @Temp Values(2, 'sqlDenis')
Insert Into @Temp Values(3, 'sqlCasey')
Insert Into @Temp Values(4, 'AlexCuse')
Declare @SortOrder VarChar(1)
Set @SortOrder = '[!]2[/!]'
Select Id,
Name
From @Temp
Order By Case When @SortOrder = '1' Then Convert(VarChar(10), Right(Replicate('0', 10) + Convert(VarChar(10), Id), 10))
When @SortOrder = '2' Then Name
End
CREATE PROCEDURE [dbo].[IL_ExportHomes_Select_ByCustId_kl]
@CustId int,
@SortOrder varchar(100)
AS
BEGIN
SET NOCOUNT ON;
SELECT h.homeid, h.hometitle, h.homelocation, t.hometype,
h.homeprice, h.homeactive, h.homeopen, h.homeorder,
e.LiveDealFeature
FROM homes h , hometypes t, exporthomes e
WHERE h.hometypeid = t.hometypeid AND h.homeid = e.homeid
AND h.custid = @CustId AND h.homeactive <> 0
ORDER BY CASE
WHEN @SortOrder = '' THEN h.homeprice desc, h.homeorder
WHEN @SortOrder = 'e.LiveDealFeature desc' THEN e.LiveDealFeature desc
WHEN @SortOrder = 'e.LiveDealFeature' THEN e.LiveDealFeature
WHEN @SortOrder = 'h.homeTitle desc' THEN h.homeTitle desc
WHEN @SortOrder = 'h.homeTitle' THEN h.homeTitle
WHEN @SortOrder = 'h.homeLocation desc' THEN h.homeLocation desc
WHEN @SortOrder = 'h.homeLocation' THEN h.homeLocation
WHEN @SortOrder = 't.homeType desc' THEN t.homeType desc
WHEN @SortOrder = 't.homeType' THEN t.homeType
WHEN @SortOrder = 'h.homePrice desc' THEN h.homePrice desc
WHEN @SortOrder = 'h.homePrice' THEN h.homePrice
WHEN @SortOrder = 'h.homeOpen desc' THEN h.homeOpen desc
WHEN @SortOrder = 'h.homeOpen' THEN h.homeOpen
END
END
WHEN @SortOrder = 'e.LiveDealFeature desc' THEN e.LiveDealFeature desc
CREATE PROCEDURE [dbo].[IL_ExportHomes_Select_ByCustId_kl]
@CustId int,
@SortOrder varchar(100),
@AscDesc int
AS
if @AscDesc = 1
Begin
SELECT h.homeid, h.hometitle, h.homelocation, t.hometype,
h.homeprice, h.homeactive, h.homeopen, h.homeorder,
e.LiveDealFeature
FROM homes h , hometypes t, exporthomes e
WHERE h.hometypeid = t.hometypeid AND h.homeid = e.homeid
AND h.custid = @CustId AND h.homeactive <> 0
ORDER BY CASE
WHEN @SortOrder = 'e.LiveDealFeature' THEN e.LiveDealFeature
WHEN @SortOrder = 'h.homeTitle' THEN h.homeTitle
WHEN @SortOrder = 'h.homeLocation' THEN h.homeLocation
WHEN @SortOrder = 't.homeType' THEN t.homeType
WHEN @SortOrder = 'h.homePrice' THEN h.homePrice
WHEN @SortOrder = 'h.homeOpen' THEN h.homeOpen
END
Desc
End
Else
Begin
SELECT h.homeid, h.hometitle, h.homelocation, t.hometype,
h.homeprice, h.homeactive, h.homeopen, h.homeorder,
e.LiveDealFeature
FROM homes h , hometypes t, exporthomes e
WHERE h.hometypeid = t.hometypeid AND h.homeid = e.homeid
AND h.custid = @CustId AND h.homeactive <> 0
ORDER BY CASE
WHEN @SortOrder = 'e.LiveDealFeature' THEN e.LiveDealFeature
WHEN @SortOrder = 'h.homeTitle' THEN h.homeTitle
WHEN @SortOrder = 'h.homeLocation' THEN h.homeLocation
WHEN @SortOrder = 't.homeType' THEN t.homeType
WHEN @SortOrder = 'h.homePrice' THEN h.homePrice
WHEN @SortOrder = 'h.homeOpen' THEN h.homeOpen
END
Asc
End
Now that I read what I posted, might be able to put an if statement for just the Desc and Asc.
IL_ExportHomes_Select_ByCustId_kl 570, 'h.homeTitle desc'
alter PROCEDURE [dbo].[IL_ExportHomes_Select_ByCustId_kl]
@CustId int,
@SortOrder varchar(100)
AS
BEGIN
SET NOCOUNT ON;
IF @SortOrder = ''
BEGIN
SELECT h.homeid, h.hometitle, h.homelocation, t.hometype,
h.homeprice, h.homeactive, h.homeopen, h.homeorder,
e.LiveDealFeature
FROM homes h , hometypes t, exporthomes e
WHERE h.hometypeid = t.hometypeid AND h.homeid = e.homeid
AND h.custid = @CustId AND h.homeactive <> 0
ORDER BY h.homeprice desc, h.homeorder
END
ELSE IF @SortOrder LIKE '%desc%'
BEGIN
SELECT h.homeid, h.hometitle, h.homelocation, t.hometype,
h.homeprice, h.homeactive, h.homeopen, h.homeorder,
e.LiveDealFeature
FROM homes h , hometypes t, exporthomes e
WHERE h.hometypeid = t.hometypeid AND h.homeid = e.homeid
AND h.custid = @CustId AND h.homeactive <> 0
ORDER BY CASE
WHEN @SortOrder = 'e.LiveDealFeature desc' THEN e.LiveDealFeature
WHEN @SortOrder = 'h.homeTitle desc' THEN h.homeTitle
WHEN @SortOrder = 'h.homeLocation desc' THEN h.homeLocation
WHEN @SortOrder = 't.homeType desc' THEN t.homeType
WHEN @SortOrder = 'h.homePrice desc' THEN h.homePrice
WHEN @SortOrder = 'h.homeOpen desc' THEN h.homeOpen
END
DESC -- descending order
END
ELSE
BEGIN
SELECT h.homeid, h.hometitle, h.homelocation, t.hometype,
h.homeprice, h.homeactive, h.homeopen, h.homeorder,
e.LiveDealFeature
FROM homes h , hometypes t, exporthomes e
WHERE h.hometypeid = t.hometypeid AND h.homeid = e.homeid
AND h.custid = @CustId AND h.homeactive <> 0
ORDER BY CASE
WHEN @SortOrder = 'e.LiveDealFeature' THEN e.LiveDealFeature
WHEN @SortOrder = 'h.homeTitle' THEN h.homeTitle
WHEN @SortOrder = 'h.homeLocation' THEN h.homeLocation
WHEN @SortOrder = 't.homeType' THEN t.homeType
WHEN @SortOrder = 'h.homePrice' THEN h.homePrice
WHEN @SortOrder = 'h.homeOpen' THEN h.homeOpen
END
ASC -- ascending order
END
END