big expressions ins derived column

  • sometimes the expressions are really big (well not so but big enough for the one line space there).

    Is there a way to include an expression created in other module (let's there is a kind o module o node only to create and edit expressions) in a derived column expression place?

    (I hope the question is clear, english is only my second language)

  • oskaroh (12/30/2011)


    sometimes the expressions are really big (well not so but big enough for the one line space there).

    Is there a way to include an expression created in other module (let's there is a kind o module o node only to create and edit expressions) in a derived column expression place?

    (I hope the question is clear, english is only my second language)

    Sounds like you are writing your queries in the query designer?

    I like to write queries in a text window, this way I can use multi line expressions, additionally, this contributes to my knowledge of the sql language syntax through practice.

    LOL feel free to tell me how little help this reply is!

  • Are you perhaps looking for a view solution? Views are a great way to encapsulate reusable logic, but from a set-based perspective.

    Additionally, you may want to investigate user-defined functions, just keep in mind the performance implications.

  • It seems its not clear, my question is:

    is there a "node" where you can build a expression more comfortably than that little space in the "derived column" node. And then you just can link to that node or something. Thanks

  • You refer to a 'derived column' - you are looking for a way to define a very complex computed column (at the table level) is this correct?

  • Sure... Do it in the normal query editor and then copy and paste...

    Jared
    CE - Microsoft

  • SQLKnowItAll (1/5/2012)


    Sure... Do it in the normal query editor and then copy and paste...

    do you mean the sql management studio query editor?

    using "new lines" (end of line) is allowed in the expression textfield?

    well im going to try...

  • oskaroh (1/29/2012)


    SQLKnowItAll (1/5/2012)


    Sure... Do it in the normal query editor and then copy and paste...

    do you mean the sql management studio query editor?

    using "new lines" (end of line) is allowed in the expression textfield?

    well im going to try...

    There are plenty of ways to script SQL operations using plain text, in fact, I haven't found many things that are impossible to do with SQL server without SQL Server Management Studio. Even if you still prefer SQL Server Management Studio, you don't necessarily have to use the table or view designers, you can create your tables and views with regular text editors and paste them into the query window.

    Here is an example of a table creation script I found on the web with a derived column:

    CREATE TABLE ExpiryThingy

    (

    ExpiryDate DATETIME,

    Expired AS (CASE

    WHEN (ExpiryDate < getDate()) THEN '** Expired **'

    ELSE '** Valid **'

    END)

    )

    (from http://www.bottleit.com.au/Blog/post/Use-a-computed-or-calculated-column-in-SQL-Server.aspx)

    As you can see, the column "Expired" has a definition with carriage returns.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply