Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Stuck converting a string!

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,52040
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Stuck converting a string!
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Stuck converting a string! - 9/20/2007 2:26:35 AM   
  JBarbea1

 

Posts: 20
Score: 0
Joined: 3/27/2007
Status: offline
Hey all!
I'm looking for a little assistance as I am an amature in comparison to most of you folks.

My delema has to do with SQL, ASP, and VBSCRIPT

I have an SQL Statement:

SELECT *
FROM database.table
WHERE Course_Name IN ('MMColParam6')

MMColParam6 = varCourseTest

varCourseTest = ("test1,test2,test3") and subsquently other values (its dynamic in nature)

but SQL Says it has to be in this format:
Course_Name IN ('test1','test2','test3') if I am using multiple values, which I will be.

What I am getting is ('test1,test2,test3') - its treating my value as one string, and Im not sure how to remedy that.

I need those tidbits as characters rather than a string.  I tried adding the characters in there but it still treats them as a single string.

Does this make any sense to anyone?
 
 
Post #: 1
 
 RE: Stuck converting a string! - 9/20/2007 2:34:25 AM   
  ehvbs

 

Posts: 2058
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi JBarbeal,

I don't think that it is possible to use parameters for an
IN clause; see

  http://www.visualbasicscript.com/fb.aspx?m=51227

Sorry to be destructive.

ehvbs

(in reply to JBarbea1)
 
 
Post #: 2
 
 RE: Stuck converting a string! - 9/20/2007 2:42:02 AM   
  JBarbea1

 

Posts: 20
Score: 0
Joined: 3/27/2007
Status: offline
When I use intergers it works fine cause SQL sees it as it needs it, and the integers are passed as a 1 parameter.  I just dont know how to pass the string parameter

IN (1,2,3,4)

but when I use strings, it needs
IN ('one','two','three','four')

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: Stuck converting a string! - 9/20/2007 2:59:42 AM   
  JBarbea1

 

Posts: 20
Score: 0
Joined: 3/27/2007
Status: offline
Maybe this will help.

What if I was to search the parameter for the ' value and replace it

this is what the constructed string for the sql statement looks like: (summary)

varCourseTest = " test1','test2','test3 "
rsMyCourseStudents__MMColParam6 = varCourseTest

recordset.Source = "SELECT *  FROM database.table  WHERE Course_Name IN ('" + Replace(rsMyCourseStudents__MMColParam6, "'", "''") + "')"

is this statement replacing the ' from string?

(in reply to ehvbs)
 
 
Post #: 4
 
 RE: Stuck converting a string! - 9/20/2007 3:07:49 AM   
  JBarbea1

 

Posts: 20
Score: 0
Joined: 3/27/2007
Status: offline
Oh my, I have a solution, boy I feel proud.

I changed the statement:
"SELECT *  FROM database.table  WHERE Course_Name IN ('" + Replace(rsMyCourseStudents__MMColParam6, "'", "''") + "')"

to:
"SELECT *  FROM database.table  WHERE Course_Name IN ('" + (rsMyCourseStudents__MMColParam6) + "')" 

and the statement works fine and the values I want are returned!

so now the output looks like this

test1','test2','test3

soooooooo cool! 

(in reply to JBarbea1)
 
 
Post #: 5
 
 RE: Stuck converting a string! - 9/20/2007 3:19:23 AM   
  ehvbs

 

Posts: 2058
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Congratulations!

(in reply to JBarbea1)
 
 
Post #: 6
 
 RE: Stuck converting a string! - 9/20/2007 3:31:15 AM   
  JBarbea1

 

Posts: 20
Score: 0
Joined: 3/27/2007
Status: offline
Thanks for you help, stimulated me that much more with the link that you provided!

I shall refer you!

(in reply to ehvbs)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Stuck converting a string! Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts