Solved

SQL function

Posted on 2014-11-21
3
208 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 48

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help Required 3 108
Text file into sql server 5 32
MS SQL / SQL Server Native Client -- how to prevent seeing other servers? 2 36
TSQL convert date to string 4 34
It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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