Hello,
I am currently trying to put the following code into a custom query in workflow which will pull down information into fields in a document. My workflow code looks a bit different but the logic is the same. I want to perform a query based on user input. I do not know how to perform this because I get errors when I use if statements.
/* Declare variables to store user input */ DECLARE @RefNo VARCHAR ( 25 ) = NULL , @Serial VARCHAR ( 25 ) = NULL , @CPFile VARCHAR ( 25 ) = NULL /* ===================================== */ /* Set variables to query */ SET @RefNo = NULL SET @Serial = NULL SET @CPFile = NULL /* ====================== */ /* Correspondence Logic ======================================================================================================= -- If ( User Input (Serial) != NULL ) = WHERE (Serial = User Input) -- If (User Input (Reference) != NULL ) = WHERE (Reference = User Input) -- If (User Input (CPFile AND Reference != NULL ) = WHERE (CPFile = User Input AND Reference = User Input ) -- If (User Input (Reference AND Serial != NULL ) = WHERE (Reference = User Input AND Serial = User Input) -- If (User Input (All) != NULL ) = WHERE (All = User Input) ======================================================================================================= */ /* === If user input for the CPFile Number and Reference Number fields are NULL and Serial is populated === ======================================================================================================== */ IF ( ( @CPFile IS NULL ) AND ( @RefNo IS NULL ) AND ( @Serial IS NOT NULL ) ) SELECT -- From PAGE0 Table ATLB.dbo.PAGE0.CompanyNm , ATLB.dbo.PAGE0.ConsumerNm , ATLB.dbo.PAGE0.CPFileNo , ATLB.dbo.PAGE0.defld , ATLB.dbo.PAGE0.RefNo , ATLB.dbo.PAGE0.Staff , ATLB.dbo.PAGE0.InitType , -- From TypeLaw Table ATLB.dbo.Typelaw.TypeName , -- From NOTES Table ATLB.dbo.NOTES.DUEDATE , ATLB.dbo.NOTES.NOTEBY , ATLB.dbo.NOTES.NOTETYPE , ATLB.dbo.NOTES.SERIAL FROM [ATLB].[dbo].[PAGE0] INNER JOIN ATLB.dbo.Typelaw ON ( PAGE0.TYPELAW = ATLB.dbo.Typelaw.Serial ) INNER JOIN ATLB.dbo.NOTES ON ( PAGE0.SERIAL = NOTES.CaseSerial ) WHERE ( ATLB.dbo.NOTES.SERIAL = @Serial ) /* =============================================== End =================================================== */ /* ======================================================================================================= */ /* If user input for the CPFile Number and Serial fields are NULL and Reference Number is populated ======================================================================================================= */ ELSE IF ( ( @CPFile IS NULL ) AND ( @Serial IS NULL ) AND ( @RefNo IS NOT NULL ) ) SELECT -- From PAGE0 Table ATLB.dbo.PAGE0.CompanyNm, ATLB.dbo.PAGE0.ConsumerNm, ATLB.dbo.PAGE0.CPFileNo, ATLB.dbo.PAGE0.defld, ATLB.dbo.PAGE0.RefNo, ATLB.dbo.PAGE0.Staff, ATLB.dbo.PAGE0.InitType, -- From TypeLaw Table ATLB.dbo.Typelaw.TypeName, -- From NOTES Table ATLB.dbo.NOTES.DUEDATE, ATLB.dbo.NOTES.NOTEBY, ATLB.dbo.NOTES.NOTETYPE, ATLB.dbo.NOTES.SERIAL FROM [ATLB].[dbo].[PAGE0] INNER JOIN ATLB.dbo.Typelaw ON ( PAGE0.TYPELAW = ATLB.dbo.Typelaw.Serial ) INNER JOIN ATLB.dbo.NOTES ON ( PAGE0.SERIAL = NOTES.CaseSerial ) WHERE ( RefNo = @RefNo ) /* =============================================== End =================================================== */ /* ======================================================================================================= */ /* === If user input for the CPFile Number is NULL and Reference Number and Serial Number are populated === ======================================================================================================== */ ELSE IF ( ( @CPFile IS NULL ) AND ( @RefNo IS NOT NULL ) AND ( @Serial IS NOT NULL ) ) SELECT -- From PAGE0 Table ATLB.dbo.PAGE0.CompanyNm , ATLB.dbo.PAGE0.ConsumerNm , ATLB.dbo.PAGE0.CPFileNo , ATLB.dbo.PAGE0.defld , ATLB.dbo.PAGE0.RefNo , ATLB.dbo.PAGE0.Staff , ATLB.dbo.PAGE0.InitType , -- From TypeLaw Table ATLB.dbo.Typelaw.TypeName , -- From NOTES Table ATLB.dbo.NOTES.DUEDATE , ATLB.dbo.NOTES.NOTEBY , ATLB.dbo.NOTES.NOTETYPE , ATLB.dbo.NOTES.SERIAL FROM [ATLB].[dbo].[PAGE0] INNER JOIN ATLB.dbo.Typelaw ON ( PAGE0.TYPELAW = ATLB.dbo.Typelaw.Serial ) INNER JOIN ATLB.dbo.NOTES ON ( PAGE0.SERIAL = NOTES.CaseSerial ) WHERE ( ( RefNo = @RefNo ) AND ( ATLB.dbo.NOTES.SERIAL = @Serial ) ) /* =============================================== End =================================================== */ /* ======================================================================================================= */ /* ============================ If user input for all fields is populated =============================== ======================================================================================================= */ ELSE SELECT -- From PAGE0 Table ATLB.dbo.PAGE0.CompanyNm , ATLB.dbo.PAGE0.ConsumerNm , ATLB.dbo.PAGE0.CPFileNo , ATLB.dbo.PAGE0.defld , ATLB.dbo.PAGE0.RefNo , ATLB.dbo.PAGE0.Staff , ATLB.dbo.PAGE0.InitType , -- From TypeLaw Table ATLB.dbo.Typelaw.TypeName , -- From NOTES Table ATLB.dbo.NOTES.DUEDATE , ATLB.dbo.NOTES.NOTEBY , ATLB.dbo.NOTES.NOTETYPE , ATLB.dbo.NOTES.SERIAL FROM [ATLB].[dbo].[PAGE0] INNER JOIN ATLB.dbo.Typelaw ON ( PAGE0.TYPELAW = ATLB.dbo.Typelaw.Serial ) INNER JOIN ATLB.dbo.NOTES ON ( PAGE0.SERIAL = NOTES.CaseSerial ) WHERE ( ( RefNo = @RefNo ) AND ( ATLB.dbo.NOTES.SERIAL = @Serial ) AND ( CPFileNo = @CPFile ) ) /* =============================================== End =================================================== */ /* ======================================================================================================= */
Thanks for any help!