I have a Program that will auto run each night, run a query, and email results. In my program I am calling a function as part of the query... What i\'d like to is pass the
To call this function in VB.Net code, you should place the function call in a Stored Procedure and call this Procedure from VB.NET, passing the parameters as follows:
Dim sqlcmd As New SqlClient.SqlCommand()
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.CommandText = "PROCEDURE_NAME"
sqlcmd.Parameters.Add(New SqlClient.SqlParameter("@startdate", DateTime.Now.Date))
sqlcmd.Parameters.Add(New SqlClient.SqlParameter("@enddate", DateTime.Now.Date.AddDays(1).AddSeconds(-1)));
Dim obj As Object = sqlcmd.ExecuteScalar()
If you can't create a Stored Procedure, you can do at the query level:
declare @startdate datetime
declare @enddate datetime
set @startdate = cast(floor(cast(getdate() as float))as datetime) -- truncate the time part
set @enddate = dateadd(S, -1, dateadd(d, 1, @startdate)) -- add 1 day, subtract 1 minute from today