Home Forums SQL Server 2005 SQL Server Newbies How to Refer to A Computed Column in Access-SQL Database Query RE: How to Refer to A Computed Column in Access-SQL Database Query

  • pete.trudell (8/20/2008)


    I appreciate your information, however I don't understand any of it. What is CTE? That is why I came in under Novice as I have never used SQL before and I have been struggling to find some reference to Access and SQL to under stand the differences. But no one has a clue.... They just send me information that is Greek , and I don't speak the language.

    But, I do appreciate the attempt. Sorry.

    Pete

    Okay, CTE stands for Common Table Expression and was introduced in SQL Server 2005. In this instance, all we are doing is creating a defined query that can be used in the later part of your query. This way, we can create the computed columns and then reference those computed columns. You can get a lot more information in Books Online (help that comes with the SQL Server tools).

    The other option is called a derived table (using a query in the from clause), again so we can reference the computed columns in our outer query.

    Another option would be to create a view with your computed columns and then use that view in your stored procedure:

    CREATE VIEW dbo.MyView AS

    SELECT [columns]

    ,computed_column1

    ,computed_column2

    FROM your_table

    WHERE somecriteria_if_needed

    GO

    Then in your stored procedure you would just reference the view.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs