-
RE: Order by an expression.
> Hi.
>
> I'm trying to sort a table with an expression in a stored procedure. Like
> this :
> SELECT * FROM ___ ORDER BY @T
>
> But this won't work.
>
> Does anyone have a good idea to solve that?
>
> Regards...
>
> Kenneth
Make it a string, and EXEC() it:
DECLARE @SQL varchar(255)
SET @SQL = 'SELECT * FROM MyTable ORDER BY ' + @T
EXEC(@SQL)
--
Colin McGuigan
Hi Colin.
When I try to do that, it comes out with an error: Error converting varchar
to int.
How should I declare the variable @t in the SP?
Thanks for your help so far.
Regards.
Kenneth
-
Re: Order by an expression.
Kenneth <ridder@snoopymail.com> wrote in message
news:39c1dfa4$1@news.devx.com...
> Hi Colin.
>
> When I try to do that, it comes out with an error: Error converting
varchar
> to int.
>
> How should I declare the variable @t in the SP?
>
> Thanks for your help so far.
>
> Regards.
>
> Kenneth
As a varchar, preferably:
If it's part of the stored proc declaration:
CREATE PROCEDURE MyProcedure
@T varchar(50)
AS
Or if it's just declared on it's own:
DECLARE @T varchar(50)
--
Colin McGuigan
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks