Selecting year value from date field

  • Hello all!

    I have a simple issue but couldn't resolve it yet. About four years ago I managed to build Reporting Services project using SQL Server 2005 Express edition with Advanced Services and BIDS. I needed to visualize all parish data by years, quarters, months and services that me as orthodox priest provide to faithful ones.

    When I tried this afternoon to do the same in new project it didn't work. I have database Parish, table Payments and column PaymentDate as one of many columns in it. I want to get year from field PaymentDate by using T-SQL statement which follows

    USE Parish

    GO

    SELECT DATEPART(yy, Payments.PaymentDate) AS Year.

    When I run that statement SQL Server "tells" me that it couldn't find specific table or column.

    Any suggestions?

    Sincerely yours

    Fr. Ivan Delic

    Serbia

  • priest Ivan Delic (10/25/2013)


    Hello all!

    I have a simple issue but couldn't resolve it yet. About four years ago I managed to build Reporting Services project using SQL Server 2005 Express edition with Advanced Services and BIDS. I needed to visualize all parish data by years, quarters, months and services that me as orthodox priest provide to faithful ones.

    When I tried this afternoon to do the same in new project it didn't work. I have database Parish, table Payments and column PaymentDate as one of many columns in it. I want to get year from field PaymentDate by using T-SQL statement which follows

    USE Parish

    GO

    SELECT DATEPART(yy, Payments.PaymentDate) AS Year.

    When I run that statement SQL Server "tells" me that it couldn't find specific table or column.

    Any suggestions?

    Sincerely yours

    Fr. Ivan Delic

    Serbia

    Can you post the whole select statement and the exact error message? If what you posted is the entire query it certainly won't work because there is no FROM clause. You also should consider naming your column alias something other than Year so you don't have to wrestle with reserved words. Something like PaymentYear is better. It not only is not a reserved word, but also it gives some meaning to the column by indicating what the year belongs to.

    _______________________________________________________________

    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/

  • Sean,

    thanks for pointing out that there is not FROM clause in my statement. That solved out my issue, thanks a lot for advice.

    Sincerely grateful

    Fr. Ivan Delic

    Serbia

Viewing 3 posts - 1 through 2 (of 2 total)

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