SQL Question

Results 1 to 2 of 2

Thread: SQL Question

  1. #1
    Jason Guest

    Default SQL Question

    Is there a better way to do this? I don&#039;t know all that much about SQL.<BR><BR>sSQL = "select ProdID,Name,SellPrice from Products where "<BR>For i = 1 to gnTotalItems<BR>&nbsp;&nbsp;sSQL = sSQL & "ProdID=&#039;" & gaItem(ID,i) & "&#039;"<BR>&nbsp;&nbsp;&#039;append "or" for all but last item<BR>&nbsp;&nbsp;if (i &#060; gnTotalItems) Then sSQL = sSQL & " or " <BR>Next<BR>

  2. #2
    keith5000 Guest

    Default RE: SQL Question

    that way will work pretty well, although you can also try using the IN statement in SQL. the IN statement works like this:<BR><BR>SELECT *<BR>FROM Products<BR>WHERE ProdID IN (1,4,5,10,11,14,19,33)<BR><BR>if you could convert &#039;gaItem&#039; to a comma delimited list, then you would say:<BR><BR>sSQL = "select ProdID,Name,SellPrice from Products "_<BR> & "where ProdID IN (" & gaItem_list & ")"<BR><BR>the difference between this solution and your original one is not much in terms of processing time. but i would recommnd using this SQL IN solution if &#039;gaItem&#039; is already coming from a comma delimited list. otherwise you&#039;ll be adding much more processing (converting an array to a list) for nothing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts