dbTalk Databases Forums  

Sorting Using Results of Subquery?

comp.databases.ms-access comp.databases.ms-access


Discuss Sorting Using Results of Subquery? in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Patrick A
 
Posts: n/a

Default Sorting Using Results of Subquery? - 03-29-2010 , 04:46 PM






All,

I have a query I need to ORDER BY by either;
a) The result of another query (always a single text string, e.g;
"TBL_Timers.TimerPos DESC".
b) a variable containing that result.

Is there any way for me to do this? (I'm calling the query from VB
via a DataGridView table adaper, so I don't think I can string the SQL
together in a module.)

I've gotten as far as verifying I can see my variable (SortStr) in a
query result set (just to prove to myself I'm building it correctly).
It comes back as "TBL_Timers.TimerPos DESC" w/o quotes.

But I can't seem to figure out how to insert (npi) it into my SQL
code.

I thought I could use

SELECT TBL_Timers.TimerID, TBL_Timers.TimerPos
FROM TBL_Timers order by SortStr();

But the results don't sort.

Any suggestions?

Am I going about this wrong?

Thanks,

Reply With Quote
  #2  
Old   
Rich P
 
Posts: n/a

Default Re: Sorting Using Results of Subquery? - 03-30-2010 , 12:47 PM






It sounds like you are pulling data from an Access mdb to a VB.Net
application. If this is the case you can try something like this from
the VB.Net app:

Imports System
Imports System.Data
Imports System.Data.OleDB

Public Class something

Dim da As OleDBDataAdapter, conn as OleDBConnection
Dim ds As Dataset

Private Sub Form1_Load(...) Handles MyBase.Load

conn = New OleDbConnection
conn.ConnectionString = "provider=microsoft.jet.oledb.4.0; Data Source =
C:\test\db1.mdb;Jet OLEDB:database Locking Mode=0;Mode=Share Deny None"

da = New OleDbDataAdapter
ds = New DataSet

da.SelectCommand = New OleDbCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandType = CommandType.Text
da.SelectCommand.CommandText = "Select * from Table1 Order By fldx"
da.Fill(ds, "tbl1")
Datagridview1.DataSource = ds.Tables("tbl1")

End Sub

End Class

hth

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #3  
Old   
Patrick A
 
Posts: n/a

Default Re: Sorting Using Results of Subquery? - 03-30-2010 , 04:36 PM



Rich,

Thanks, works like a charm!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.