Solved

combining date with string as a parameter in sql filter

Posted on 2013-10-28
3
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to transfer Notes from Outlook 2010 to OneNote 2016 16 269
What the difference between blend and Visual Studio 3 285
Problem to open text file 11 136
Why use this lambda? 12 61
I have put this article together as i needed to get all the information that might be available already into one general document that could be referenced once without searching the Internet for the different pieces. I have had a few issues where…
The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

763 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