Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / July 2008

Tip: Looking for answers? Try searching our database.

How to write SQL function?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SF - 24 Jul 2008 08:50 GMT
Hi,

I have the follwoing in many views, I think it would be wise to create a
function (scalar??) so that I can reuse it in the future.

SELECT ...
CASE WHEN dbo.tblEvents.EventDate BETWEEN '20061001' AND
                     '20070930' THEN 'FY 07' WHEN dbo.tblEvents.EventDate
BETWEEN '20071001' AND
                     '20080930' THEN 'FY 08' WHEN dbo.tblEvents.EventDate
BETWEEN '20081001' AND '20090930' THEN 'FY 09' END AS [Fiscal Year]
...

Could someone direct me?

SF
Erland Sommarskog - 24 Jul 2008 10:45 GMT
> I have the follwoing in many views, I think it would be wise to create a
> function (scalar??) so that I can reuse it in the future.
[quoted text clipped - 8 lines]
>
> Could someone direct me?

I would suggest that it is even better to have a table:

  CREATE TABLE FYmap (thedate datetime NOT NULL,
                      [Fiscal Year] char(5) NOT NULL,
                      CONSTRAINT pk_FYmap PRIMARY KEY (thedate))

Signature

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Mariano Gomez - 24 Jul 2008 14:02 GMT
You are better off creating a fiscal period table where you can store this
information.

Best regards,
--
MG.-
Mariano Gomez, MIS, MCP, PMP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com

> Hi,
>
[quoted text clipped - 12 lines]
>
> SF
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.