Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL statement
Message
De
25/08/2005 18:14:43
Al Doman (En ligne)
M3 Enterprises Inc.
North Vancouver, Colombie Britannique, Canada
 
 
À
24/08/2005 13:36:16
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Versions des environnements
Environment:
C# 1.1
Database:
MS SQL Server
Divers
Thread ID:
01043492
Message ID:
01044128
Vues:
9
>In my VFP applications, I join fields together in many of my SQL statements using a VFP table. As such:
>
> SELECT mytable.field1, ALLTRIM(mytable.field2) + "-" + ALLTRIM(mytable.field3) AS mycolumn FROM mytable INTO CURSOR c_mycursor
>
>Is there any way to do something like this using Asp.Net and SQL Server?

I'd consider setting up a View in SQL Server. The view would have to be defined using Transact-SQL and its functions, but T-SQL has both LTRIM() and RTRIM() functions. So, you could do something like
CREATE VIEW MyView

AS

SELECT 
    Field1, 
    LTRIM(RTRIM(Field2)) + "-" + LTRIM(RTRIM(Field3)) AS MyColumn
    FROM MyTable
The view is like a virtual Table, so from ADO.NET or any other client you would simply issue SELECT * FROM MyView ...

One nice thing about using Views is that if, later on, you need to tweak the formatting of its contents, you just do it in the view definition, rather than having to chase down all the places in your client code that manually build the columns the way you want them.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform