Migrating asp.net code (VB.net) to use functions and subroutines as parameters.
Using MS Server Management Studio to create said functions and subs.
Would like to test the functions from within MS SMS before testing them via the web page.
Here’s an example. Say I have a function called “dbo.getNumber”
I’m trying to test it using the following:
USE [someDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
declare @value int;
select @value = dbo.getNumber;
print @value;
go
When I type F5 (to run the “query”) it gives the following msg:
“The name “dbo.getNumber” is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.”
The function dbo.getNumber was accepted just fine, btw. (It’s counting records of a database that meet certain criteria.)
Hopefully you can infer from the non-working code what I am trying to do.
How can I print the value of a function (for testing purposes) from within SMS?
Correct solution as per James Johnson, below:
USE [someDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
declare @value int;
select @value = dbo.getNumber();
print @value;
go
Note the parens for the function invocation.
Note also: intellisense in SMS underlines dbo.getNumber() as if it were an error, but running the query with F5 works and outputs the right result.
You need to call it like this: