As far as I know, SQL doesn't have a currentdate function, you should use GetDate() and the syntax is as follows:
This would be correctly written as
If datepart(Month,getdate()) between 1 and 3
Begin
Select "Post_Date"
From Transaction_History
Where datepart(month, "Post_Date" between 10 and 12
Else
Next If and condition
Begin
Select ...
From ...
Where ...
END
You could also use case when ...
For SQL Syntax refer to Microsoft SQL Server Books On Line (BOL) for more information.
Let me know if you need more help. If you are looking for a book on writing Stored Procedures, The Gurus Guide is a decent one.
I don't know if you've mentioned what database you use in another post, but GetDate() is a Sybase and SQLServer function. If you're writing against Oracle, use SysDate.
unfortunately am getting error messages with formula (by the way database is Sybase). Below is formula in its entireity. Error messages are Incorrect syntax on lines 31, 36, 42, 48, 54, 61, and 67. Any help appreciated.
31 If datepart(Month,getdate()) between 1 and 3
32 Begin
33 Select "Post_Date"
34 From Transaction_History
35 Where datepart(month, "Post_Date" between 10 and 12
36 Else if
37 datepart(Month,getdate()) between 4 and 6
38 Begin
39 Select "Post_Date"
40 From Transaction_History
41 Where datepart(month, "Post_Date" between 1 and 2
42 Else if
43 datepart(Month,getdate()) between 7 and 9
44 Begin
45 Select "Post_Date"
46 From Transaction_History
47 Where datepart(month, "Post_Date" between 4 and 6
48 else if
49 datepart(Month,getdate()) between 10 and 12
50 Begin
51 Select "Post_Date"
52 From Transaction_History
53 Where datepart(month, "Post_Date" between 7 and 9
54 and if
55 datepart(Month,getdate()) between 1 and 3
56 Begin
57 Select "Post_Date"
58 From Transaction_History
59 Where datepart(year, "Post_Date" = datepart
60 (year,getdate(-1))
61 Else
62 Begin
63 Select "Post_Date"
64 From Transaction_History
65 Where datepart(year, "Post_Date" = datepart
66 (year,getdate())
67 END
Queries you have regarding your procedure should probably be aimed at the Sybase forum. But, for the record, if you have an appropriate version of Crystal, using the Calendar1stQtr to Calendar4thQtr functions saves a lot of range typing.
The last version of Sybase I worked with was SQL Anyshere 5.5 so I cannot recall all the syntatical requirements. I think that you need to get assistance from a Sybase DBA. Do you have access to one?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.