Hi all,
My goal here is to have a stored procedure lookup a table value and return another column value that is incremented (counter column). If the lookup value doesn't exist then the SP will take the input values from the Forms tokens to make a new row in the table starting at 1.
So problem 1. I made a SP but it doesn't show up in the lookup rules dropdown for the table... what am I doing wrong?
2. I don't know if I have my SP correct or not. I'm not a SQL guru but I can muddle my way through if I know what I'm looking at (reverse engineer here). This is the code I'm trying to use, and it's probably wrong :).
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Joe Fabre -- Create date: 06/20/2017 -- Description: Create or Update the Counter for a C.A.R.s by project -- ============================================= CREATE PROCEDURE CAR_Counter_Update -- Add the parameters for the stored procedure here @ProjectName nvarchar(100) = 0, @NextCARNum int = 1 AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Check to see if Project exists in table IF NOT EXISTS (SELECT * From CARCounter Where ProjectName = @ProjectName) --If project doesn't exist then insert variable value which holds ProjectName token from the form and --and start Counter at '1' Begin Insert into CARCounter (ProjectName, Counter) values (@ProjectName, @NextCARNum) end --If Project exists in table increment the counter by one and return the new value to Forms to use in field Else Update CARCounter SET Counter = Counter + @NextCarNum Set @NextCARNum = Counter Where ProjectName = @ProjectName END GO
Thanks for the help in advance. Looking forward to the people smarter than me here on Forms and SQL to help out :).