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
 SQL Server Development (2000)
 T-SQL - Converting nvarchar to numeric

Author  Topic 

taylo
Yak Posting Veteran

82 Posts

Posted - 2000-12-06 : 20:49:13
Here is a tough one. My T-SQL script will ORDER BY whatever
field the user is searching by. Most of my fields are nvarchar
but a couple are numeric. Birthday and Sponsor in the Case statement
are genrating errors as they are both numeric. Does anyone
know what the syntax would be for converting @searchcrit to
a numeric date type? That way I can use it to validate the
first 4 fields then change it's data type and validate the last 2.

CREATE PROCEDURE SP_Search

@groopeid numeric(10),
@searchcrit nvarchar(50)

AS
Select FirstName,LastName,SiteMembers.Email,Birthday,City,ClassYear,Joined from GroopeMembers INNER JOIN SiteMembers on SiteMembers.ParentNumber =
GroopeMembers.UserID Where Groope = @groopeid ORDER BY

CASE @searchcrit
When 'FirstName' then FirstName
When 'LastName' then LastName
When 'SiteMembers.Email' then SiteMembers.Email
When 'City' then City
When 'Birthday' then Birthday <--numeric
When 'Sponsor' then Sponsor <-- numeric
else
LastName
End

Thanks,

Rob
   

- Advertisement -