Stuck converting a string!

Author Message
JBarbea1

  • Total Posts : 20
  • Scores: 0
  • Reward points : 0
  • Joined: 3/27/2007
  • Status: offline
Stuck converting a string! Thursday, September 20, 2007 3:26 AM (permalink)
0
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?
 
#1
    ehvbs

    • Total Posts : 3321
    • Scores: 110
    • Reward points : 0
    • Joined: 6/22/2005
    • Location: Germany
    • Status: offline
    RE: Stuck converting a string! Thursday, September 20, 2007 3:34 AM (permalink)
    0
    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

     
    #2
      JBarbea1

      • Total Posts : 20
      • Scores: 0
      • Reward points : 0
      • Joined: 3/27/2007
      • Status: offline
      RE: Stuck converting a string! Thursday, September 20, 2007 3:42 AM (permalink)
      0
      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')
       
      #3
        JBarbea1

        • Total Posts : 20
        • Scores: 0
        • Reward points : 0
        • Joined: 3/27/2007
        • Status: offline
        RE: Stuck converting a string! Thursday, September 20, 2007 3:59 AM (permalink)
        0
        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?
         
        #4
          JBarbea1

          • Total Posts : 20
          • Scores: 0
          • Reward points : 0
          • Joined: 3/27/2007
          • Status: offline
          RE: Stuck converting a string! Thursday, September 20, 2007 4:07 AM (permalink)
          0
          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! 
           
          #5
            ehvbs

            • Total Posts : 3321
            • Scores: 110
            • Reward points : 0
            • Joined: 6/22/2005
            • Location: Germany
            • Status: offline
            RE: Stuck converting a string! Thursday, September 20, 2007 4:19 AM (permalink)
            0
            Congratulations!
             
            #6
              JBarbea1

              • Total Posts : 20
              • Scores: 0
              • Reward points : 0
              • Joined: 3/27/2007
              • Status: offline
              RE: Stuck converting a string! Thursday, September 20, 2007 4:31 AM (permalink)
              0
              Thanks for you help, stimulated me that much more with the link that you provided!

              I shall refer you!
               
              #7

                Online Bookmarks Sharing: Share/Bookmark

                Jump to:

                Current active users

                There are 0 members and 1 guests.

                Icon Legend and Permission

                • 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
                • Read Message
                • Post New Thread
                • Reply to message
                • Post New Poll
                • Submit Vote
                • Post reward post
                • Delete my own posts
                • Delete my own threads
                • Rate post

                2000-2012 ASPPlayground.NET Forum Version 3.9