I have tried several variations but just can't seem to get it working right.It will return an empty string:CREATE PROCEDURE [dbo].[AddInfo] @UserID VARCHAR(10), @Chemicals dbo.chemical_list_tbltype READONLY, @msg VARCHAR(MAX) OUTPUT, @errMessage VARCHAR(512) OUTPUTASBEGIN DECLARE @Name VARCHAR(256) DECLARE @RowsToProcess INT DECLARE @CurrentRow INT SET @msg = '' - set to empty string first SET @RowsToProcess = 10 SET @CurrentRow = 0 WHILE @CurrentRow < @RowsToProcess BEGIN SET @CurrentRow = @CurrentRow + 1 SELECT @Name = 'Ethanol' --Hard coded for testing IF NOT EXISTS(SELECT 1 FROM Chemicals WHERE Name = @Name) BEGIN INSERT INTO Chemicals(Name) VALUES(@Name) END ELSE BEGIN --DECLARE @tmp VARCHAR(MAX) --SET @tmp = @msg --SET @msg = @tmp + @Name --Returns empty string --SET @msg = @msg + @Name + '<br />' --Returns empty string SET @msg += @Name --Returns empty string --SET @msg += 'test' --Returns empty string --SET @msg = 'test' --This works --SET @msg += '<br />' --Returns empty string END ENDENDGO
I am positive the Names I am inputting are repeats and it does hit the else statement.Why will this not work?Thanks!PROBLEM SOLVEDDecided to check something so I set @msg = 'test' before the while loop.Then, what I needed worked.So, I set it to SET @msg = ''I suppose you need to set the parameter from NULL to empty string first.