Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Random quote for the day..
Message
 
 
À
12/04/2009 16:14:24
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01394387
Message ID:
01394450
Vues:
50
>>>>>>What's a better way to do a random "quote for the day"?
>>>>>
>>>>>What is your back-end?
>>>>>
>>>>>In SQL Server to generate a random record you will use
>>>>>
>>>>>select top 1 * from myTable order by NewID()
>>>>>
>>>>>In VFP I would agree with Sergey about generating random record using rand() function.
>>>>
>>>>Does that really work in SQL Server? I had not thought of using NewID in that way.
>>>
>>>Yes it works, because NewID generates a GUID which is a 128 bits random integer.
>>
>>The part I didn't (don't?) understand is how those IDs are associated with existing records in the table.
>
>
>In VFP you coudl order by like this:
>
>
select firstName+lastName as fullName,firstName,lastName from myTable order by fullName
>or:
>
select firstName+lastName as fullName,firstName,lastName from myTable order by 1
>
>but not like this:
>
select firstName,lastName from employees order by firstName+lastName
when you don't need that calculated column in result (just using in ordering).
>
>In SQL server however all of these are valid:
>
>
select firstName+lastName as fullName,firstName,lastName from myTable order by fullName
>
select firstName+lastName as fullName,firstName,lastName from myTable order by 1
>
select firstName,lastName from myTable order by firstName+lastName
>
>In the same manner you could do:
>
>
select newId(),* from mytable order by 1
>
>or:
>
>
select * from mytable order by newID()
>
>Cetin

Gee, folks, I know how VFP works ;-) It was the ability to order a SQL Server query by an expression not to be found (even concatenated) in the table that I was unaware of.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform