Solved

SQL function

Posted on 2014-11-21
3
206 Views
Last Modified: 2014-11-21
Hi
I have 2 functions and not sure what it does and why structured this way.

Fun_a:

Create function x()
Return table
As
Return
(Select distinct ID from fun_b(getdate()) as result)
Go

Fun_b:
Create function fun_b(@asifdate datetime)
Return table
As
Return
(
Select distinct cc as ID
 ( select a,s,f from tbl
Where year = '2014') as result)
Go

What are these getdate and why two functions when get date is not used within query?
0
Comment
Question by:shmz
3 Comments
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 250 total points
ID: 40457325
It doesn't make sense unless you have a function called ID.

I'm surprised if that runs.

You are correct - getdate() is not used within the second query, so it's redundant.
0
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 250 total points
ID: 40457329
GETDATE() is used to pass the current date & time to the 2nd function since it has a datetime parameter (@asifdate).
But you're right, the parameter isn't used at all. Maybe it should since year='2014' is hardcoded and I think the idea should be year = year(@asifdate).
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40457336
Did you inherit these functions, and what are you trying to do here?
'What the hell is this?' is not the most actionable question.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

832 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