Solved

combining date with string as a parameter in sql filter

Posted on 2013-10-28
3
383 Views
Last Modified: 2013-10-28
Hello,

I am trying to put a filter in sql 2008 view for the date field. I have the current year year(getdate()) and I need to use a string '8/31/' as a permanent month and day so the parameter will be '8/31/2013' and the next year '8/31/2014'. I am trying to do this
 '8/31/'+year(getdate()) but getting an error "Conversion failed when converting the varchar value '8/31/' to datatype int." How  I can write it correctly?
0
Comment
Question by:kqureshi321
3 Comments
 
LVL 2

Accepted Solution

by:
deast05 earned 500 total points
ID: 39606672
The year(getdate()) portion is treated like a number and SQL is attempting to perform addition.  You'll want to convert it to a string by doing something similar to:

select '8/31/' + convert(varchar(4), year(getdate()))
from table1
0
 

Author Closing Comment

by:kqureshi321
ID: 39606684
Great, Thank you very much.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39607648
or you can use "datename" which returns a character string

select '8/31/' + datename(year,getdate() )
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
Viewers will learn the different options available in the Backstage view in Excel 2013.

746 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

10 Experts available now in Live!

Get 1:1 Help Now