Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

combining date with string as a parameter in sql filter

Posted on 2013-10-28
3
Medium Priority
?
395 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:Galina Besselyanova
3 Comments
 
LVL 2

Accepted Solution

by:
deast05 earned 2000 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:Galina Besselyanova
ID: 39606684
Great, Thank you very much.
0
 
LVL 49

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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
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 …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

877 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