we have stored procedure created user can write comma separated search tags in software product's admin. can add comma-separated tags , in case if wants edit them, read table tags, recreate them comma-separated values (csv) in stored procedure , returns calling code. happened recently, user complained not see new csvs wrote. looked , found out stored procedure truncating string when reads values database , creates csv string. string of type nvarchar, , because exceeding max characters of 4000 limit, values gets truncated. ideas on how work out problem.
find code underneath.
begin begin declare @synonyms table ( rowid int identity(1,1), synonymid int, [synonym] nvarchar(4000) ); set nocount on; insert @synonyms(synonymid, [synonym]) select distinct synonymid, [synonym] rf_searchsynonyms with(nolock) searchtermid = @searchtermid , activeind = 1 if((select count(rowid) @synonyms) <> 0) begin declare @currentrow int = (select min(rowid) @synonyms), @totalrows int = (select max(rowid) @synonyms), @synonyms_csv nvarchar(4000) = ''; while @currentrow <= @totalrows begin declare @tempsyn nvarchar(500); select @tempsyn = [synonym] + ',' @synonyms rowid = @currentrow; set @synonyms_csv = @synonyms_csv + ltrim(rtrim(lower(@tempsyn))); set @currentrow = @currentrow + 1 end end else begin set @synonyms_csv = ''; end end begin declare @skus table ( rowid int identity(1,1), skuid int, sku nvarchar(15) ); set nocount on; insert @skus(skuid, sku) select distinct skuid, sku rf_searchskus with(nolock) searchtermid = @searchtermid , activeind = 1 if((select count(rowid) @skus) <> 0) begin declare @currentrow1 int = (select min(rowid) @skus), @totalrows1 int = (select max(rowid) @skus), @skus_csv nvarchar(4000) = ''; while @currentrow1 <= @totalrows1 begin declare @tempsku nvarchar(15); select @tempsku = sku + ',' @skus rowid = @currentrow1; set @skus_csv = @skus_csv + ltrim(rtrim(@tempsku)); set @currentrow1 = @currentrow1 + 1 end end else begin set @skus_csv = ''; end end begin declare @combined varchar(8000), @syn_len int = 0, @sku_len int = 0; select @syn_len = len(@synonyms_csv); select @sku_len = len(@skus_csv); select @combined = @synonyms_csv + '-_-' + @skus_csv; select @synonyms_csv + '-_-' + @skus_csv; end
end
i can't use text , ntext not play nice concatenation operations.
thanks.
how declaring string parameter?
nvarchar(max)
supports 2^32-1 (2gb)
see link.
Comments
Post a Comment