Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 I would like to add an order by filter to the data

Author  Topic 

iftikhar
Starting Member

3 Posts

Posted - 2011-05-01 : 11:49:10
Dear experts,

I have this following sql query which is working fine. however, I would like to add a sort feature (order by TitleName)to the following sql query.

Thanks in advance for your time.

Private Sub List2_Click()

On Error Resume Next

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset

'conn.Open "dsn=cool"

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\control\sys\exercise.binar"
conn.Open


List3.Clear



intType = list2.ItemData(list2.ListIndex)


Set rs = conn.Execute("select product.TitleName, product.txtSentence, product.category, Product.prodid, category.id from product Inner Join category on product.category = category.id where category.id = " & intType)


'List3.RightToLeft = True

Do Until rs.EOF

List3.AddItem rs("txtSentence")

List3.ItemData(List3.NewIndex) = rs("prodid")


rs.MoveNext

Loop

txtVocabCat.Text = intType

rs.Close

'---

List3.ListIndex = 0
'
''====================

End Sub

-------------------------------------------------------

I tried the following but does NOT work:

Set rs = conn.Execute("select product.TitleName, product.txtSentence, product.category, Product.prodid, category.id from product Inner Join category on product.category = category.id where category.id = " & intType) order by titleName ASC

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-05-01 : 11:53:08
Set rs = conn.Execute("select product.TitleName, product.txtSentence, product.category, Product.prodid, category.id from product Inner Join category on product.category = category.id where category.id = " & intType & " order by product.TitleName")

Woud be easier to put this in a stored proceure with category.id as a parameter.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

iftikhar
Starting Member

3 Posts

Posted - 2011-05-01 : 11:57:09
Thanks nigelrivett

Let me try now and be back.
Go to Top of Page

iftikhar
Starting Member

3 Posts

Posted - 2011-05-01 : 12:03:10
Perfect!

Thanks so much nigelrivett. I can not appreciate you enough for it. I was struggling with it for few hours. May Allah bless you in both the worlds.
Go to Top of Page
   

- Advertisement -