Solved

Date to String Conversion

Posted on 2008-06-20
2
2,187 Views
Last Modified: 2010-04-21
Does anyone know why this won't work in Sybase but works in MS SQl

I have an Stored Procedure.  I want to get the current month end from a string and return the value as a string '20080429'

So I pass in string '20080429'
and it returns a string '20080430'
This is want I've written but it doesn't work....

CREATE PROCEDURE Caoimhe @value_dt varchar(8)
as
declare @current_monthend varchar(8)
declare @monthend varchar(8)
select @monthend = CONVERT( varchar(8), dateadd(day, -1,dateadd(month, 1,convert(datetime,left(@value_dt,6) + '01',112))), 112)

return @monthend
0
Comment
Question by:MickeyMin
2 Comments
 
LVL 19

Accepted Solution

by:
grant300 earned 500 total points
ID: 21832912
Assuming ASE.  Please confirm which Sybase product and version you are using.

It works fine for me...

begin
declare @value_dt varchar(8)
set @value_dt = '20080423'
select CONVERT( varchar(8), dateadd(day, -1,dateadd(month, 1,convert(datetime,left(@value_dt,6) + '01',112))), 112)
end

Returns "20080430"

Oh, I see what the issue is.  You are trying to use the RETURN statement to get the output value.  That is a no-no for stored procedures.  You really need to use a stored function.

ASE v15 supports T-SQL function and the CREATE FUNCTION syntax.  You are trying to use the CREATE PROCEDURE syntax.  With a procedure, any return value other than 0 is seen as an error.

If you are using a version of Sybase prior to 15, you do not have the function syntax available to you.  You have one or two choices: you can call the procedure with the @monthend as and OUTPUT argument or, if you have it licensed, you can create a Java SQL function that will do what you want as well.

Regards,
Bill
0
 

Author Closing Comment

by:MickeyMin
ID: 31469129
Thank you!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Advantage DB snapshots, replication or mirroring 2 421
SQL Query 2 336
connect to sybase then query 1 744
How to use a TRY CATCH in Sybase SQL syntax. Or something similar? 1 90
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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