Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql Order by

Status
Not open for further replies.

nina21

Programmer
Feb 1, 2011
3
IN
Under ASP, I have this statement which works:
strSQL="select * from " & Table_Name
objRS.open strSQL, objConn

But when I want to sort according to my column 'Position' (which is of number type under Access 2000) It no longer works. Any Idea?:
strSQL="select * from " & Table_Name & " Order by Position"
objRS.open strSQL, objConn

I have this error:
error '80004005'
Unspecified error

I'm connected this way:
StrConnect = "Provider=Microsoft.Jet.OLEDB.4.0;"&_
"Data Source=o:\teams\pursuit\db\productdb.mdb;" &_
"Persist Security Info=False"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = StrConnect
objConn.Open
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.activeconnection = objConn

Help
 
strSQL="select * from " & Table_Name & " Order by Position"

I'm not familiar with Position. I thought you could only use ASC or DESC? ====================================
I love people. They taste just like
chicken!
 
Scratch what I just posted.

I had 2 hours of sleep last night.

Lol....what was I thinking. ====================================
I love people. They taste just like
chicken!
 
Try this

strSQL="select * from " & Table_Name & " Order by" & Position

or writing it like this put single quotes around the double ones.

strSQL="select * from '" & Table_Name & "' Order by Position"


or a combo of the 2

strSQL="select * from '" & Table_Name & "' Order by" & Position

I hate unspecified errors try that.
AJ
I would lose my head if it wasn't attached. [roll1]
 
I have received errors in similar situations using rs.open, try using a command object instead:
Set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = strConnect
objCommand.CommandText=strSQL
objCommand.CommandType=adCmdText
Set objRS = objCommand.Execute
Set objCommand = Nothing
I have found .Open to be finicky about sql other than "SELECT * FROM Table" unless flags are set appropriately, and I think the database flags are a pain so I do it my way :)
-tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Thanks
It works well without the Order By.
But with it, I have the same error.
 
Hmm, is Position an actual attribute in your table that is being requested? Can you do a "SELECT Position FROM " & Table_Name
If not, then the issue isn't the SQL or the connection, but the fact that it actually can't find the attribute/field you are looking for in order to order by it.
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Thanks
Don't search my name of field 'position' was a key word.
Now with the name 'iPosition' it works.
Bye
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top