ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 4th, 2003, 04:41 PM
PGrimpo PGrimpo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 2 PGrimpo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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???

Reply With Quote
  #2  
Old August 5th, 2003, 04:12 PM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
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))

Reply With Quote
  #3  
Old August 9th, 2003, 01:27 AM
zimm zimm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 30 zimm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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)))

Reply With Quote
  #4  
Old August 9th, 2003, 06:58 PM
WineIsGood's Avatar
WineIsGood WineIsGood is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: New York
Posts: 49 WineIsGood User rank is Private First Class (20 - 50 Reputation Level)WineIsGood User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 m 51 sec
Reputation Power: 6
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Converting string types in Stored Procedure


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway