|
-
Dec 26th, 2003, 01:52 AM
#1
Thread Starter
Lively Member
Stored Procedure Order By Variable
I want to query my table with a stored procedure with a way for the user of my program to change how the data is ordered.
So I wrote my Stored procedure out like this...
Code:
CREATE PROCEDURE spVerifyComplete
(
@Order1 as column,
@Order2 as column
)
As
SELECT
*
FROM RSR
WHERE (RSRCompleted = "NO"
ORDER BY @Order1, @Order2
GO
But it don't work.
Can someone tell me what I did wrong?
Thanks,
-Ober
-
Dec 30th, 2003, 04:58 AM
#2
Its not going to work this way.
You need to assign the whole query to a variable and use the exec statement to run it correctly.
Cheers,
Abhijit
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Dec 30th, 2003, 10:44 AM
#3
WHERE (RSRCompleted = "NO"
---------^
could it be that?
-
Dec 31st, 2003, 08:31 AM
#4
Fanatic Member
As abhijit said:
Code:
CREATE PROCEDURE spVerifyComplete
(
@Order1 as column,
@Order2 as column
)
As
Declare @Sql varchar(8000)
Set @Sql = 'Select * '
Set @Sql = @Sql + 'From RSR '
Set @Sql = @Sql + 'Where Completed = "NO" '
Set @Sql = @Sql + 'Order By ' + @Order1 + ', ' + @Order2
Exec (@Sql)
Chris
Master Of My Domain
Got A Question? Look Here First
-
Dec 31st, 2003, 08:52 AM
#5
Thread Starter
Lively Member
Yup,
I wrote that after working all day/night on Christmas day.
By morning of the day after Christmas, I was tired and when your tired and not to mention hungry its hard to find the simple errors.
I cannot connect to the SQL server from home so I'll have to go to work and fix it. ::sigh::
Thanks for your help.
-Ober
-
Jan 1st, 2004, 07:35 PM
#6
Hyperactive Member
Column datatype?!?! Also, list the specific table columns in an SQL statement.
-
Jan 13th, 2004, 01:32 PM
#7
Lively Member
Originally posted by OberCanober
Yup,
-Ober
Can this work with LIKE in a where clause. I attempted to use this with LIKE and % and I get a syntax error.
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
|
Click Here to Expand Forum to Full Width
|