Using IN to fetch records

Results 1 to 3 of 3

Thread: Using IN to fetch records

  1. #1
    Join Date
    Dec 1969

    Default Using IN to fetch records

    Hello I am using IN to fetch specified records from my SQL server DB as below:<BR><BR>Select Project_id,Client_type_id from project_master where Client_type_id IN(5,2,1,3,7,6)<BR><BR>But I want the records of client_Ids to be the way I specified in the IN. Instead it will be in ascending order. Appreciate if you could help me out in this regard

  2. #2
    Join Date
    Dec 1969

    Default RE: Using IN to fetch records

    to be honest, that&#039;s tricky in SQL Server. see here :<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default I'd do this in ASP code...

    Trippy asked the same question a while back & I wrote up a way to do it in ASP.<BR><BR>&#060;%<BR>list = Request("multipleSelectionFormField")<BR><BR>SQL = "SELECT id, name FROM table WHERE ID IN (" & list & ")"<BR>Set RS = conn.Execute( SQL )<BR>data = RS.GetRows( )<BR>RS.Close<BR><BR>inArray = Split( list, ", " )<BR>For i = 0 To UBound(inArray)<BR> curid = inArray(i)<BR> For row = 0 To UBound(data,2)<BR> If curid = data(0,row) Then<BR> ... dump out the info for this row ...<BR> Exit For<BR> End If<BR> Next<BR>Next<BR>%&#062;<BR><BR>Quick and dirty and simple.<BR><BR>Of course, passing the data back to the client *UNSORTED* (HINT: GetString()!) and letting the client do that ordering is even better.<BR><BR>

Posting Permissions

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