question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MS SQL call function (not stored procedure)

See original GitHub issue

Hello.

I have a simple scalar-value sql function like

CREATE FUNCTION [dbo].[f_cost_1] RETURNS int AS BEGIN return 2000 END

And I`ve tried to call it from a .NETCoreApp 2.0 application like

var cost = db.ExecuteReader("f_cost_1"); //return empty reader or var cost = db.ExecuteProc<int>("f_cost_1"); //return 0 or var cost = db.Execute<int>("f_cost_1"); //return 0

It works great with a stored procedure like

CREATE PROCEDURE [dbo].[f_cost_1] as begin select 2000 end

So how can I call a function properly and get return int result?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
MaceWinducommented, Aug 9, 2019

I will mark it as feature request. To review if it makes sense to instroduce some helper like T Sql.Function<T>(name, params)

0reactions
MaceWinducommented, Aug 9, 2019

Then don’t close it yet 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can we not execute a stored procedure inside ...
You cannot execute a stored procedure inside a function, because a function is not allowed to modify database state, and stored procedures ......
Read more >
Execute a SQL Server procedure inside a function
According to Microsoft standard, stored procedures cannot be executed inside the function, but technically it is possible with some tweaks. How ...
Read more >
Calling a Function From a Stored Procedure in SQL Server
In this article, we will see how to call a function from a stored procedure in SQL Server. In this article, we will...
Read more >
Difference between Functions and Stored Procedures in ...
Functions can be called from a Select statement. Stored procedures cannot be called from a Select/Where or Having statements. Execute statement ...
Read more >
Function vs. Stored Procedure in SQL Server
1 Answer ; The function always returns a value. Stored Procedure will not return a value, but the procedure can return “0” or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found