?
Solved

Syntax question for SQL Stored Procedure

Posted on 2007-03-21
2
Medium Priority
?
182 Views
Last Modified: 2010-03-20
Hi Experts

I need to create a date string then do a test against it with another date within a SQL Stored Procedure. So I am first of all extracting the Year I want into a variable called @FinancialYr then need to set a date of 1/4/@FinancialYr.

My existing code is;

set @FinancialYrStart = cast(("01/04/"&@FinancialYr) as datetime)
print  convert(datetime, @FinancialYrStart)

The second line is where I am trying to view the result. I am getting an error ;
"Syntax error converting the varchar value '01/04/' to a column of data type int."

Can anyone give me an idea where the syntax is falling down ?

Many thanks
RangerLad
0
Comment
Question by:RangerLad
[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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 18762729
the error is in line 1, where you do the concat of the string 01/04/ with the variable.
here a corrected  version:

set @FinancialYrStart = convert(datetime, "01/04/" + cast ( @FinancialYr as varchar(4)) , 101 )
print  @FinancialYrStart
0
 

Author Comment

by:RangerLad
ID: 18762757
Thanks angelIII thats exactly the result I was looking for, many thanks

RangerLad
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 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