Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL statement
Message
From
25/08/2005 18:14:43
 
 
To
24/08/2005 13:36:16
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Environment versions
Environment:
C# 1.1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01043492
Message ID:
01044128
Views:
10
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform