Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 casting

Author  Topic 

mkapoen
Starting Member

2 Posts

Posted - 2005-06-23 : 18:28:23
Hello there,

I have this stored procedure that does not work. I read some articles but I could not find the solution.

The error message is: Syntax error converting the nvarchar value 'Display description...' to a column of data type int.

I think it has something to do with casting, I can't seem to get it fixed. Can someone please help me out? I place the code below...

Thanks in advance,
Michael

************************************************************
I call the procedure with:
EXEC Conditions_GetConditions 1
************************************************************

CREATE PROCEDURE Conditions_GetConditions

@SortOrder tinyint = NULL

AS
SELECT
con_Id,
con_name,
con_description,
con_ct_ID,
ct_name
FROM
conditions
INNER JOIN
Condition_Types
ON Condition_Types.ct_ID = conditions.con_ct_ID

ORDER BY CASE WHEN @SortOrder = 1 THEN con_description
WHEN @SortOrder = 2 THEN con_name
WHEN @SortOrder = 3 THEN ct_name
ELSE con_Id
END

RETURN
GO


x

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-23 : 19:01:48
It is due to your dynamic ORDER BY with different column data types. Check this out:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=5942

Tara
Go to Top of Page

mkapoen
Starting Member

2 Posts

Posted - 2005-06-25 : 06:53:49
Thanks,

I've got it working.
I forsee only one problem: I had to convert a integer to a nvarChar.
Selecting an integer geives another result than selecting a nvarChar.
for instance:

1 1
11 2
2 3
23 11
3 23
etc.

x
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-27 : 01:32:44
Post sample data and the query you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -