Ask a Question related to ASP Database, Design and Development.
-
TomB #1
Sort By parameter?
I'd like to sort my stored procedure by the column name I pass in...how
would I do so?
CREATE PROCEDURE dbo.spHelpDeskGetItemsForHistory
(
@SortBy varchar(11),
@SortDirection varchar(4)
)
AS
SET NOCOUNT ON
SELECT tblHelpDeskCategories.DisplayName AS Category,
tblHelpDeskProblems.DateTimeStamp AS DateTime,
tblHelpDeskProblems.BriefDesc AS Description,
tblPeople.FName, tblPeople.LName
FROM tblHelpDeskProblems
INNER JOIN
tblPeople
ON tblHelpDeskProblems.UserID = tblPeople.PersonID
INNER JOIN
tblHelpDeskCategories
ON tblHelpDeskProblems.CategoryID = tblHelpDeskCategories.ID
ORDER BY [@SortBy] @SortDirection
TomB Guest
-
Sort by id
Now I simple forum by Dreamweaver i use "repeat region" for show data in database . It show like this 1 2 3 4 but i want to show -
Sort bug
It appears that the runtime cannot sort a datagrid column when the items in the column contain a NaN or Infinity. Is there a way to override the... -
Date Parameter For Saved Parameter Queries
Hi again, I finally got to using saved parameter queries in my application (a big thank you to Bob Barrows for helping me with this). Currently... -
memory sort and disk sort
I check the sysprofile table and find there are 700 times disk sort, I think it is lack of sort memory. I want to turn all the disk sort into the... -
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB.
Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. hi, guys i have asp... -
Bob Barrows #2
Re: Sort By parameter?
TomB wrote:
One way is to use dynamic sql:> I'd like to sort my stored procedure by the column name I pass
> in...how would I do so?
> .
[url]http://www.algonet.se/~sommar/dynamic_sql.html[/url]
Another is to use CASE<snip>>
> CREATE PROCEDURE dbo.spHelpDeskGetItemsForHistory
> (
> @SortBy varchar(11),
> @SortDirection varchar(4)CASE WHEN @sortby='DisplayName' AND @SortDirection> ORDER BY
='ASC' THEN DisplayName ELSE 0 END ASC,
CASE WHEN @sortby='DisplayName' AND @SortDirection
='DESC' THEN DisplayName ELSE 0 END DESC,
etc.
HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows Guest
-
Aaron Bertrand [MVP] #3
Re: Sort By parameter?
> > ORDER BY
In addition, a trick I learned (at least when dealing with positive numeric> CASE WHEN @sortby='DisplayName' AND @SortDirection
> ='ASC' THEN DisplayName ELSE 0 END ASC,
> CASE WHEN @sortby='DisplayName' AND @SortDirection
> ='DESC' THEN DisplayName ELSE 0 END DESC,
columns) is to use:
CASE @sortby
WHEN 'IntColumn' THEN
CASE @sortDirection
WHEN 'ASC' THEN IntColumn
ELSE -IntColumn END
...
END
Aaron Bertrand [MVP] Guest
-
Tom B #4
Re: Sort By parameter?
Thanks, I thought I was missing something.
"Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
news:um9DWJ$nDHA.1632@TK2MSFTNGP10.phx.gbl...> TomB wrote:> One way is to use dynamic sql:> > I'd like to sort my stored procedure by the column name I pass
> > in...how would I do so?
> > .
> [url]http://www.algonet.se/~sommar/dynamic_sql.html[/url]
>
> Another is to use CASE> <snip>> >
> > CREATE PROCEDURE dbo.spHelpDeskGetItemsForHistory
> > (
> > @SortBy varchar(11),
> > @SortDirection varchar(4)> CASE WHEN @sortby='DisplayName' AND @SortDirection> > ORDER BY
> ='ASC' THEN DisplayName ELSE 0 END ASC,
> CASE WHEN @sortby='DisplayName' AND @SortDirection
> ='DESC' THEN DisplayName ELSE 0 END DESC,
> etc.
>
> HTH,
> Bob Barrows
>
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>
Tom B Guest



Reply With Quote

