stored-procedure issue, nvarchar 2 small, can't pass varchar(8000)

Ok, I have this code:
DECLARE @EventID varchar(500)
DECLARE @FieldID varchar(500)
declare       @SQLstring nvarchar(4000)
set @EventID = '407'
set @FieldID = '7240, 7241, 7242, 7243, 7244'

      -- Written by Ivan Kabanov (expo@ru.ru) 4/28/2005 - Reporting Procedure
      set @SQLstring = 'SELECT FieldID,
                        FormID,
                        Name
                  INTO ##Temp1
                  FROM dbo.FormFields
                  where Fieldid in (' + @fieldid + ')'
      exec(@SQLstring)
      
      set @SQLstring ='SElECT a.EventID,
                        a.FieldID,
                        a.UserID,
                        a.Response
                  INTO ##Temp1Response
                  FROM dbo.FormFieldResponse a
                  where a.eventid in (' + @eventID + ')
                        and a.responseID = (select Max(b.ResponseID)
                                          from dbo.FormFieldResponse b
                                          where b.eventid = a.eventid
                                                and b.fieldid = a.fieldid
                                                and b.userid = a.userid)'
      
      exec(@SQLstring)

      set @SqlString = ''


-- Uzaem Dynamic Sql chtobi sozdat stroku dlya execute.
-- Sozdaem Pivot Table stroku that has the fields field name as an alias from the field table.
SELECT @SqlString = coalesce(@SqlString,'')  + ' min(case B.FieldID when ' + ltrim(Str(A.FieldID)) + ' then Response end) as [' + Name + '],'
FROM ##Temp1 A
JOIN ##Temp1Response B on A.fieldId = b.FieldID
WHERE Charindex(',' + ltrim(Str(A.FieldID)) +',', ',' + @FieldID + ',') > 0 AND Charindex(',' + ltrim(Str(B.EventID)) +',', ',' + @EventID + ',') > 0

-- Uberaem poslednuu zapyatuu snova
Set @SqlString = SUBSTRING(@SqlString,1, len(@SqlString) -1)


-- Berem obe stroki i logim ih v odnu select statement.
SET @SqlString = 'SELECT EventID, B.UserID, LastName, FirstName, Organization, FormID, ' + @SqlString + '
                  FROM ##Temp1 A
                  JOIN ##Temp1Response B on A.fieldId = b.FieldID
                  JOIN UserInfo C on B.UserID = C.UserID
                  WHERE A.FieldID in (' + @FieldID + ') AND B.EventID in (' + @EventID + ')
                  Group by EventID, B.UserID, LastName, FirstName, Organization, FormID
                  Order by EventID'

-- select @SqlString
exec sp_executeSql @SqlString, N'@FieldID varchar(500), @EventID varchar(500)', @FieldID, @EventID

print @sqlstring


When I execute it, it won't return all data, cuz nvarchar(4000) is limited, so I tried varchar(8000) - still no use, cuz sp_executeSql expecting nvarchar it says.
So how can I make it work?
LVL 1
sushestvoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RDWaibelCommented:
have you tried:

SET @SqlString = N'SELECT EventID, B.UserID, LastName, FirstName, Organization, FormID, ' + @SqlString + '
               FROM ##Temp1 A
               JOIN ##Temp1Response B on A.fieldId = b.FieldID
               JOIN UserInfo C on B.UserID = C.UserID
               WHERE A.FieldID in (' + @FieldID + ') AND B.EventID in (' + @EventID + ')
               Group by EventID, B.UserID, LastName, FirstName, Organization, FormID
               Order by EventID'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sushestvoAuthor Commented:
Yes, That definetely won't work.

Anyway, topic is closed. Problem solved.
arbertCommented:
So close the question....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.