Click here to Skip to main content
15,887,822 members
Home / Discussions / Database
   

Database

 
AnswerRe: Multiple values in stored proc parameter Pin
Mark J. Miller12-Mar-07 5:39
Mark J. Miller12-Mar-07 5:39 
GeneralRe: Multiple values in stored proc parameter Pin
GaryWoodfine 12-Mar-07 5:45
professionalGaryWoodfine 12-Mar-07 5:45 
QuestionUpdating order of DataTables Pin
Satish3212-Mar-07 4:36
Satish3212-Mar-07 4:36 
QuestionData Group on Week: Pin
Shahzad.Aslam12-Mar-07 1:22
Shahzad.Aslam12-Mar-07 1:22 
AnswerRe: Data Group on Week: Pin
Harini N K12-Mar-07 1:43
Harini N K12-Mar-07 1:43 
AnswerRe: Data Group on Week: Pin
Bad Programmer13-Mar-07 15:40
Bad Programmer13-Mar-07 15:40 
GeneralRe: Data Group on Week: Pin
Shahzad.Aslam13-Mar-07 18:50
Shahzad.Aslam13-Mar-07 18:50 
QuestionDynamic sort order in SQL stored proc Pin
GaryWoodfine 12-Mar-07 0:31
professionalGaryWoodfine 12-Mar-07 0:31 
Hey Guys I know this question has probably been asked a thousand times on this forumm, but I had a look and been searching on the net for an answer, and no one answer suits my situation.

I have a Stored proc that handles paging on the server side
everything works fine, until I get to the dynamic sorting.

[code]SET NOCOUNT ON;
Declare @StartIndex int;


Set @PropCount=(SELECT COUNT(property_id ) FROM [dbo].[vwResidentialProperty]
WHERE (@Area is null or parentid = @Area)
and (@locality is null or CharIndex( [dbo].[vwResidentialProperty].locid, @Locality)>0)
and askprice between isnull(@MinPrice,0) and isnull(@MaxPrice ,5000000)
and bedrooms between isnull(@MinBed,0) and isnull(@MaxBed ,10)
and (@PropType is null or charindex( [dbo].[vwResidentialProperty].propertytype,@proptype)>0)
and floorarea between isnull(@MinFloor,0) and isnull(@MaxFloor,5000000));

/*Check to see if the Number of Properties returned is less than actual page size if it is then set the start Index
to the Property Count */
if @PropCount < @Numrow
begin
set @StartIndex = 1;
end;
else
begin
set @StartIndex = (@PageIndex * @Numrow) + 1;
end;
with Property As
(

SELECT top 100 percent
case @SortOrder
when 0 then ROW_NUMBER() OVER (order by [dbo].[vwResidentialProperty].askprice Asc)
when 1 then ROW_NUMBER() OVER (order by [dbo].[vwResidentialProperty].askprice desc)
when 2 then ROW_NUMBER() OVER (order by [dbo].[vwResidentialProperty].dateadded desc)
end as row,
[dbo].[vwResidentialProperty].property_id , [dbo].[vwResidentialProperty].Address, [dbo].[vwResidentialProperty].askprice
, [dbo].[vwResidentialProperty].dateadded, [dbo].[vwResidentialProperty].Saleterm ,[dbo].[vwResidentialProperty].locid,
[dbo].[property].adbrief
FROM [dbo].[vwResidentialProperty]
inner join [dbo].[property] on [dbo].[property].property_id = [dbo].[vwResidentialProperty].property_id
WHERE (@Area is null or parentid = @Area)
and (@locality is null or CharIndex( [dbo].[vwResidentialProperty].locid, @Locality)>0)
and [dbo].[vwResidentialProperty].askprice between isnull(@MinPrice,0) and isnull(@MaxPrice ,5000000)
and [dbo].[vwResidentialProperty].bedrooms between isnull(@MinBed,0) and isnull(@MaxBed ,10)
and (@PropType is null or charindex( [dbo].[vwResidentialProperty].propertytype,@proptype)>0)
and [dbo].[vwResidentialProperty].floorarea between isnull(@MinFloor,0) and isnull(@MaxFloor,5000000)


)
Select Property_ID, Address as 'Address', askprice as 'Price', adbrief as 'Description', Saleterm, dateadded
FROM Property
WHERE Row BETWEEN
@Startindex and (@startindex + @Numrow )-1
order by case @SortOrder
when 0 then askprice
when 1 then askprice -1
--when 2 then dateadded -1
end;[/code]

I need to be able to provide 3 different sorting options to the user.
1 . Price Asc
2. Price Desc
3. Date added Asc

Now I can't find away of providing this criteria.
At the moment the options are available to the user on screen via option buttons. I don't really want supply SQL code in the HTML of the page i.e

I would prefer to pass an integer value through to the stored proc, and let the case clause handle it.

I have tried puttin Price Asc in the case clause, but SQL complains.

is there any other way of doing this?

Kind Regards,
Gary


My Website || My Blog || My Articles

AnswerRe: Dynamic sort order in SQL stored proc Pin
Harini N K12-Mar-07 1:36
Harini N K12-Mar-07 1:36 
QuestionShould i install SQL SERVER on client Machine Pin
dotnethunk11-Mar-07 21:12
dotnethunk11-Mar-07 21:12 
AnswerRe: Should i install SQL SERVER on client Machine Pin
N a v a n e e t h11-Mar-07 21:29
N a v a n e e t h11-Mar-07 21:29 
GeneralRe: Should i install SQL SERVER on client Machine Pin
dotnethunk11-Mar-07 21:41
dotnethunk11-Mar-07 21:41 
GeneralRe: Should i install SQL SERVER on client Machine Pin
N a v a n e e t h11-Mar-07 22:26
N a v a n e e t h11-Mar-07 22:26 
QuestionView Pin
indian14311-Mar-07 20:54
indian14311-Mar-07 20:54 
AnswerRe: View Pin
Sylvester george11-Mar-07 23:50
Sylvester george11-Mar-07 23:50 
AnswerRe: View Pin
Krish - KP12-Mar-07 1:38
Krish - KP12-Mar-07 1:38 
QuestionView Pin
indian14311-Mar-07 20:52
indian14311-Mar-07 20:52 
QuestionCreating Search Index in SQL Server Pin
N a v a n e e t h11-Mar-07 20:32
N a v a n e e t h11-Mar-07 20:32 
AnswerRe: Creating Search Index in SQL Server Pin
mghiassi25-Mar-07 9:44
mghiassi25-Mar-07 9:44 
Questionabout locks Pin
Renuka Reddy11-Mar-07 19:35
Renuka Reddy11-Mar-07 19:35 
AnswerRe: about locks Pin
N a v a n e e t h11-Mar-07 20:38
N a v a n e e t h11-Mar-07 20:38 
QuestionCannot Update..theres an error Pin
blitz2bleach11-Mar-07 11:40
blitz2bleach11-Mar-07 11:40 
AnswerRe: Cannot Update..theres an error Pin
Colin Angus Mackay11-Mar-07 11:49
Colin Angus Mackay11-Mar-07 11:49 
AnswerRe: Cannot Update..theres an error Pin
Harini N K11-Mar-07 23:47
Harini N K11-Mar-07 23:47 
QuestionSqlserver 2000 and Sqlserver 2005 Pin
alav11-Mar-07 4:03
alav11-Mar-07 4:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.