• ohpenot (2/25/2013)


    Another problem linked to this one..

    The query works fine now, even if i don't like not being able to write "jprod as....query treatement here"

    What if i need to define the computed column "jprod" as persisted?

    I tried to put the keyword PERSISTED wherever it could be and i got an error in each case.

    SELECT [NUMCAM]

    ,[date_passage]

    ,[heure_passage]

    ,[anneeprod]

    ,(CASE WHEN heure_passage BETWEEN '00:00:00' and '05:59:59' THEN day(date_passage) - dbo.jprodtestannee(anneeprod)

    ELSE day(date_passage) - dbo.jprodtestannee(anneeprod) +1

    END) as jprod

    FROM dbo.GlobaldataEOLT8

    GO

    I tried to re-write the query the way i feel more comfortable with :

    ..jprod as (CASE WHEN....) PERSISTED but the error remains, can't get it solved.

    PERSISTED is used for computed columns. You are creating a view, this means the calculation will have to run everytime you select the data. If you want to avoid this you would need to add the computed column to your base table.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/