PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > Setting up a store procedure...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Setting up a store procedure...

Réponse
 
LinkBack Outils de la discussion
Vieux 20/12/2007, 16h13   #1
JJ297
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Setting up a store procedure...

I'm developing a library and want to display the alphabets across the
screen. When a user clicks on one of the alphabets I want all titles
beginning with that letter to appear on the screen.

How would I write this stored procedure?

My table is called Titles

Fields:
Title ID
Titles

Thanks!
  Réponse avec citation
Vieux 20/12/2007, 19h19   #2
Anith Sen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Setting up a store procedure...

Not sure how involved this requirement is. If you want to get the list of
alphabets from the existing titles, you can have simple query like:

SELECT DISTINCT LEFT( titles, 1 ) AS "alpha"
FROM tbl
ORDER BY "alpha" ;

In many cases, for fast searching and indexing, people implement other
alternatives. One variation is to have another table that is referenced back
to the titles table. Another one with smaller list could be a computed
column that is indexed with the expression: LEFT( titles, 1 ) etc.

If you want all the alphabets displayed regardless of existing titles, you
can easily generate them on the client side itself. Most web development
tools have build in functions that does this in a quick loop. If you want to
do this with t-SQL, you can use the CHAR() function on a simple query like:

SELECT CHAR( n )
FROM Nbrs
WHERE n BETWEEN 65 AND 90 ;

Regarding how the table Nbrs is created, see:
www.projectdmx.com/tsql/tblnumbers.aspx

--
Anith


  Réponse avec citation
Vieux 20/12/2007, 19h51   #3
Plamen Ratchev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Setting up a store procedure...

You can simply pass the letter selected by the user as a parameter to the
stored procedure and then pull the list. The stored procedure can be
something like this:

CREATE PROCEDURE GetTitles(
@letter NVARCHAR(1))
AS
SELECT title_id, title
FROM Titles
WHERE title LIKE @letter + '%'
ORDER BY title

Anith has a good suggestion to create a computed column on LEFT(title, 1)
that is indexed. Then the WHERE filter will be computed_column = @letter.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

  Réponse avec citation
Vieux 20/12/2007, 20h26   #4
JJ297
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Setting up a store procedure...

On Dec 20, 2:51 pm, "Plamen Ratchev" <Pla...@SQLStudio.com> wrote:
> You can simply pass the letter selected by the user as a parameter to the
> stored procedure and then pull the list. The stored procedure can be
> something like this:
>
> CREATE PROCEDURE GetTitles(
> @letter NVARCHAR(1))
> AS
> SELECT title_id, title
> FROM Titles
> WHERE title LIKE @letter + '%'
> ORDER BY title
>
> Anith has a good suggestion to create a computed column on LEFT(title, 1)
> that is indexed. Then the WHERE filter will be computed_column = @letter.
>
> HTH,
>
> Plamen Ratchevhttp://www.SQLStudio.com


Thanks Plamen this is easy enough and it works! Thanks Anith for your
suggestion too!
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09461 seconds with 12 queries