|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Converting string types in Stored Procedure
I have the following stored procedure:
CREATE PROCEDURE [dbo].[GET_CategoryCurrentNewsList] @Category VARCHAR AS BEGIN SELECT dbo.News_Joined.NewsTitle, dbo.News_Joined.NewsID FROM dbo.News_Joined WHERE (dbo.News_Joined.StartDate <= GETDATE()) AND (dbo.News_Joined.EndDate >= GETDATE()) AND (dbo.News_Joined.CategoryID IN (@Category)) END GO dbo.news_Joined.CategoryID is an INT, and @Category is a string such as (1000, 1010, 1020). However, no results are returned. I figured I had to do something to do some string conversions from INT to VARCHAR or something, but I can't use CSTR. I do not know how many numbers will be passed to @Category, so making seperate variables isn't an option. Any ideas??? |
|
#2
|
||||
|
||||
|
did you try typecasting? i'm using mssql ad it looks something like this
if its a number and you want a string try CAST(variablename, varchar(50)) |
|
#3
|
|||
|
|||
|
why don't you use CINT on the parameter? Comaprisons on integers are more efficient than comparisons on strings anyway.
If you are likely to have a number gt 65K you could use CLNG on both values. SELECT dbo.News_Joined.NewsTitle, dbo.News_Joined.NewsID FROM dbo.News_Joined WHERE (dbo.News_Joined.StartDate <= GETDATE()) AND (dbo.News_Joined.EndDate >= GETDATE()) AND (CLNG(dbo.News_Joined.CategoryID) IN (CLNG(@Category))) |
|
#4
|
||||
|
||||
|
You can't do that, sorry. The correct syntax would be:
SELECT .... AND ID IN (1,2,3) for example. However, you cannot pass that kind of list to SQL Server and expect it to execute. Your best bet would be to pass it as a string and then create the SQL statement in the stored procedure as a string and eval() it. Like this: create procedure myProcedure @myList as varchar(50) As declare sqlString varchar(255) select sqlString = "SELECT blah blah WHERE ID in (" + myList + ")" eval(sqlstring) -Dave |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Converting string types in Stored Procedure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|