Reputation: 153
How could i remove the last comma from a part of dynamic query
set @Query += '[A].[ID].&[' + Convert(varchar,SUBSTRING(@string, @start, @end - @start) ) +']&[CAN],[A].[ID].&[' +Convert(varchar,SUBSTRING(@string, @start, @end - @start) ) + ']&[usa],';
Upvotes: 5
Views: 7023
Reputation: 1270351
Rephrase your logic and remove the first one using stuff()
:
set @Query = ',[A].[ID].&[' + . . . ';
Then remove it as:
set @Query = stuff(@Query, 1, 1, '');
Upvotes: 1
Reputation: 93734
One common technique uses Left
and Len
function
set @Query = Left(@Query,len(@Query)-1)
Update : Run the above statement after competition of while loop/Cursor or after framing the entire query
Upvotes: 4