SQL Cstr conversion

Posted on 2006-05-06
Last Modified: 2012-05-05
This is msAccess SQL that i am trying to parse in Query Analyzer -  i am getting an error on CStr.  Can someone tell me what I need to change to to use in SQL?

CDate("01/01/" & CStr(Year([entyear])-1)
Question by:LAppling7775
    LVL 75

    Accepted Solution

    select CONVERT (datetime ,'01/01/'+ CAST(Year(GETDATE()-1) as Varchar(4)) ,103) --dd/mm/yyyy
    select CONVERT (datetime ,'01/01/'+ CAST(Year(GETDATE()-1) as Varchar(4)) ,101) --mm/dd/yyyy
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran

    select CONVERT (datetime ,'01/01/'+ CAST(Year(EntYear-1) as Varchar(4)) ,103) --dd/mm/yyyy
    select CONVERT (datetime ,'01/01/'+ CAST(Year(EntYear-1) as Varchar(4)) ,101) --mm/dd/yyyy
    LVL 5

    Assisted Solution

    convert(datetime,"01/01/" + convert(varchar(4),datepart(year,[entyear])-1) ,101)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now