Solved

combining date with string as a parameter in sql filter

Posted on 2013-10-28
3
390 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

759 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