Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that the <code>IN</code> clause <code>where UserBrDiv in(@ParmUserBrDiv)</code> isn't going to work like that so no records are actually selected. You use this in two different places, getting the <code>@maxcnt</code>, which will always be zero because of it, and then trying to update the actual table, which will never select any rows because of it. What you need to do is build this UDF in your database:</p> <pre><code>IF OBJECT_ID('dbo.CSVToTable') IS NOT NULL DROP FUNCTION dbo.CSVToTable GO CREATE FUNCTION [dbo].[CSVToTable] ( @KeyValue VARCHAR(8000), @StringInput VARCHAR(8000) ) RETURNS @OutputTable TABLE ( [KeyValue] VARCHAR(8000), [String] VARCHAR(8000) ) AS BEGIN DECLARE @String VARCHAR(10) WHILE LEN(@StringInput) &gt; 0 BEGIN SET @String = LEFT(@StringInput, ISNULL(NULLIF(CHARINDEX(',', @StringInput) - 1, -1), LEN(@StringInput))) SET @StringInput = SUBSTRING(@StringInput, ISNULL(NULLIF(CHARINDEX(',', @StringInput), 0), LEN(@StringInput)) + 1, LEN(@StringInput)) INSERT INTO @OutputTable ( [KeyValue], [String] ) VALUES ( @KeyValue, @String ) END RETURN END GO </code></pre> <p>then put this statement just above the first query you need to fix up:</p> <pre><code>SELECT String INTO #brdiv FROM dbo.CSVToTable(@ParmUserBrDiv) </code></pre> <p>and then change your queries to be this:</p> <pre><code>SELECT @maxcnt = MAX(reid) FROM [dbo].[TblRecAssignName] WHERE ReAssignName in ( SELECT LogId FROM TblUserTest WHERE UserBrDiv IN ( SELECT String FROM #brdiv ) AND ReCycle=@AssingCycle) UPDATE [OptimaUCBL].[dbo].[TblDisburseInfo] SET DisbRecAssignTo = ( SELECT ReAssignName FROM [OptimaUCBL].[dbo].[TblRecAssignName] WHERE [ReID] = @cnt AND ReAssignName in ( SELECT LogId FROM TblUserTest WHERE UserBrDiv IN ( SELECT String FROM #brdiv ) AND ReCycle=@AssingCycle ) ) WHERE [DisbID] = @tdisbid </code></pre> <p>Finally, remove the single quotes from the comma-delimited string and just delimit the values like this:</p> <pre><code>A,B,C,D,E,F,G </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload