I'm concatenating multiple table rows into one row. Below code is the working only with nvarchar data type but not with int.
- ALTER PROCEDURE [dbo].[spViewConcatenatedPolicyCInoForTaxInvoice_motorOnly]
- -- Add the parameters for the stored procedure here
- @TaxInvoiceNumber nvarchar(50)
- AS
- BEGIN
- DECLARE @MotorCINo int
- SET @MotorCINo=''
- SELECT @MotorCINo = @MotorCINo + MotorCINo +', '
- FROM CashierSalesDetails
- WHERE TaxInvoiceNumber = @TaxInvoiceNumber
- SELECT LEFT(@MotorCINo,LEN(@MotorCINo)-1) AS PolicyCINo
- END
- Msg 245, Level 16, State 1, Procedure spViewConcatenatedPolicyCInoForTaxInvoice_motorOnly, Line 17
- Conversion failed when converting the varchar value ', ' to data type int.


Rafnas T PRank #280 · 8.8K reputationPosted Mar 26, 2017, 9:58 PM EDT
Ramesh PalanivelRank #372 · 6.8K reputationPosted Mar 26, 2017, 6:54 AM EDT
cast(intName as varchar) // intname is your integer column, convert it to varchar for concatinationJes SieRank #1,285 · 1.3K reputationPosted Mar 26, 2017, 7:02 AM EDT
Ramesh PalanivelRank #372 · 6.8K reputationPosted Mar 26, 2017, 7:40 AM EDT