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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to limit my query to the 1st letter of each listing

Status
Not open for further replies.

nuwud

Programmer
Sep 3, 2010
11
US
Hi,

I started off with this post: and, thanks to BillyRayPreachersSon, found this is an SQL thing, not JavaScript. I know nothing about SQL.

So, long story short, I want to display my externally generated listing by the first letter only per page, exactly like these guys do:
The 3rd party service gave me these tools to work with, but I don't know how it works:

This is the JavaScript that calls the code into my page: <script language="javascript" type="text/javascript">
document.write('<script language="javascript" src=" Tickets"></' + 'script>');
</script>

Any ideas?
 
This is what the whole page's source looks like:

<%@ page language="C#" autoeventwireup="true" inherits="Concerts, App_Web_g65xkisr" masterpagefile="~/BasePage.master" %>


<asp:Content ContentPlaceHolderID="contentBody" ID="cntBody" runat="server">
<script language="javascript" type="text/javascript">

document.write('<script language="javascript" src=" Tickets"></' + 'script>');
</script>
</asp:Content>
 
Can't help with JS/ASP/C#, but a SQL simple query would have the format
Code:
SELECT [field] from [table] WHERE [field] LIKE 'A%'
to return all contents of [field] from
that began with the letter 'A'. Note that whether data beginning with 'a' is returned would depend on the set-up of the database.

soi là, soi carré
 
Nuwud, try a ranking function like this
Code:
SELECT [Name], 
       SUBSTRING([Name], 1,1) AS FirstLetter,
       DENSE_RANK() OVER (ORDER BY SUBSTRING([Name], 1,1)  ) AS GroupIndex
FROM DBO.Test

This and even the query by DrLex should allow you to page through the groups. I.e. user clicks on a letter and you execute the query to retrieve and display only rows that have a name starting with the selected letter.

Good luck.

MCITP SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)
 
Thanks guys!

I still don't understand where to put the SQL query code based off my current page structure. How do I format it within the C# ASPX page with JavaScript? Do I just run the query between the <asp:Content tags?

The SQL database isn't on my side, it is 3rd party side.
 
Is there an example page someone can send me to so I can get a feel for the syntax required to place those queries on my page?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top