Solved

Syntax question for SQL Stored Procedure

Posted on 2007-03-21
2
176 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
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

24 Experts available now in Live!

Get 1:1 Help Now