Solved

SQL function

Posted on 2014-11-21
3
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 50

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 66

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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