Solved

SQL function

Posted on 2014-11-21
3
200 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 45

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
In this article I will describe the Backup & Restore 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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

12 Experts available now in Live!

Get 1:1 Help Now