• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 399
  • Last Modified:

How to add a query string to an order by

I am trying to get the SQL statement to order by a URL Query String that is called category.
I can't seem to get this work.

I have tried:
"SELECT * FROM dbo.rockers ORDER BY [(Request.QueryString("category"))]"

"SELECT * FROM dbo.rockersORDER BY" &<% = Request.QueryString("category") %>

Please help.

Thank you in advance.
0
colonelblue
Asked:
colonelblue
  • 6
  • 6
  • 2
  • +3
10 Solutions
 
jimtpowersCommented:
What language are you doing this in? It will make a different on the syntax.
0
 
Paul JacksonCommented:
Should be : (ensure you get spacing right)
"SELECT * FROM dbo.rockers ORDER BY " & <% = Request.QueryString("category") %>

0
 
colonelblueAuthor Commented:
Hello I am still getting an syntax error:

Syntax error

RSRockers_cmd.CommandText = "SELECT * FROM dbo.rockers ORDER BY " & <% = Request.QueryString("category")

 It is telling me the "<" right after the ampersand is a syntaz error.

Thanks again.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Paul JacksonCommented:
make sure there is no space between <% and =

RSRockers_cmd.CommandText = "SELECT * FROM dbo.rockers ORDER BY " & <%= Request.QueryString("category")

Are you setting this on an asp or asp.net page?
0
 
colonelblueAuthor Commented:
Hello. I have made sure there is no space and still getting the same syntax error as aforementioned.
Asp classic.

Thanks again.
0
 
Paul JacksonCommented:
Is it reporting a syntax error in the ASP or when the SQL command is executed

0
 
colonelblueAuthor Commented:
This is what I get in the browser"

Microsoft VBScript compilation error '800a03ea'

Syntax error

/rockers/index.asp, line 29

Lien 29 is the aforementioned error.

Thanks again.

0
 
Paul JacksonCommented:
try :
dim sqltext = "SELECT * FROM dbo.rockers ORDER BY " & <%= Request.QueryString("category")
RSRockers_cmd.CommandText = sqltext
0
 
colonelblueAuthor Commented:
:( I got an erroe:

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/rockers/index.asp, line 29

dim sqltext = "SELECT * FROM dbo.rockers ORDER BY " & <%= Request.QueryString("category")

The cursor pointing to the "=" sign.

0
 
Paul JacksonCommented:
actually i don't think you need <%= .. %>

try:
RSRockers_cmd.CommandText = "SELECT * FROM dbo.rockers ORDER BY " & Request.QueryString("category")

if that doesn't work try:
RSRockers_cmd.CommandText = "SELECT * FROM dbo.rockers ORDER BY " & Response.Write(Request.QueryString("category"))
0
 
colonelblueAuthor Commented:
I get the same error for both:

Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near 'BY'.

0
 
colonelblueAuthor Commented:
I get the same error for both:

Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near 'BY'.

0
 
Paul JacksonCommented:
Are you sure that CAtegory is being passed in the url?
0
 
GhunaimaCommented:
What is the value displayed if you display the value of the variable sqltext after setting it with

 dim sqltext = "SELECT * FROM dbo.rockers ORDER BY " &  Request.QueryString("category")
0
 
GhunaimaCommented:
Try this
 dim sqltext = "SELECT * FROM dbo.rockers ORDER BY " &  Request.QueryString("category").tostring()
0
 
anillucky31Commented:
Try this
 dim sqltext = "SELECT * FROM dbo.rockers ORDER BY " &  Request.QueryString("category")

make sure to have space after ORDER BY and before "
0
 
Anthony PerkinsCommented:
Since this is ASP and not ASP.NET, do it this way:
Dim sqltext
sqltext = "SELECT * FROM dbo.rockers ORDER BY " & Request("category")

Response.Write sqltext       ' Post the results of this.
Response.End
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 6
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now