I have a scalar-valued function that works just fine but I don't understand where it is getting the value of its variable from (I got help with this several months ago from this forum). It is:ALTER FUNCTION [dbo].[Count_Open_Tech](@ClientRegion_ID INT) RETURNS INT AS BEGIN DECLARE @countOpenTech INT SELECT @countOpenTech = COUNT(*) FROM dbo.IOM_Tests_Patient WHERE ClientRegion_ID = @ClientRegion_ID and Tech_Sign_Off=0 and cancelled=0 and deleted=0 RETURN @countOpenTechEND
I would display the value in another table column call countOpenTech with the following computed specification: (case when [dbo].[Count_Open_Tech]([ClientRegion_ID])<(1) then (0) else [dbo].[Count_Open_Tech]([ClientRegion_ID]) end)
It is used in a website dashboard to show the techs how many patient records are NOT signed off from the table dbo.IOM_Tests_Patient. The techs can belong to different clients and regions ( thus ClientRegion_ID). I am not clear in the above code where the "@ClientRegion_ID is getting its value?What I want to do is to create another function just like this but based on the tech_ID.I have tried the following which I was successful in creating it but I was unable in placing it into a computed field with Management Studio next to the other clie:Create FUNCTION [dbo].[Count_Open_Tech_ID](@tech1_ID INT) RETURNS INT AS BEGIN DECLARE @countOpenTechID INT SELECT @countOpenTechID = COUNT(*) FROM dbo.IOM_Tests_Patient WHERE tech1_ID = @tech1_ID and Tech_Sign_Off=0 and cancelled=0 and deleted=0 RETURN @countOpenTechIDEND
I would get a column error using: (case when [dbo].[Count_Open_Tech_ID]([tech1_ID])<(1) then (0) else [dbo].[Count_Open_Tech_ID]([tech1_ID]) end)
My biggest confusion is trying to figure out how is this function suppose to pick up the variable of the tech's tech1_id? It does work correctly with the @ClientRegion_ID (the first function) but I don't get how "it" knows what the clientregion_id actually is?