faisal23
First thing i make fun in sql:
USE [ZAB_HCTMS]
GO
/****** Object: UserDefinedFunction [dbo].[LCNos] Script Date: 1/8/2019 1:09:54 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/****** Object: UserDefinedTableType [dbo].[oldTVP_ConsignmentNoteLineItems] Script Date: 1/7/2019 1:00:53 PM ******/
ALTER FUNCTION [dbo].[LCNos]
(
@LCNo NVARCHAR(MAX),
@Comma CHAR(1)
)
RETURNS @Output TABLE (
ID NVARCHAR(1000)
)
AS
BEGIN
DECLARE @StartIndex INT, @EndIndex INT
SET @StartIndex = 1
IF SUBSTRING(@LCNo, LEN(@LCNo) - 1, LEN(@LCNo)) <> @Comma
BEGIN
SET @LCNo = @LCNo + @Comma
END
WHILE CHARINDEX(@Comma, @LCNo) > 0
BEGIN
SET @EndIndex = CHARINDEX(@Comma, @LCNo)
INSERT INTO @Output(ID)
SELECT SUBSTRING(@LCNo, @StartIndex, @EndIndex - 1)
SET @LCNo = SUBSTRING(@LCNo, @EndIndex + 1, LEN(@LCNo))
END
RETURN
END
then sp for this:
-- EXEC GetLCsDetails '2188,2196,2201'
alter PROCEDURE GetLCsDetails
@LCNos VARCHAR(100)
AS
BEGIN
SELECT lr.*, lr.PayBalance 'TotalPayBalance', s.Name 'SuppName',
cb.AdvancePayment, s.[Address] 'Address',
s.PinCode, pod.SupplierBillNo
FROM LorryChallans lr
left join ConsignmentBookings cb on lr.ConsignmentBookingID =
cb.ConsignmentBookingID
left join Suppliers s on cb.VehicleSupplierID = s.SupplierID
left join POD pod on lr.ConsignmentBookingID = pod.ConsignmentBookingID
WHERE
lr.LorryChallanNumber
IN( SELECT CAST(ID AS INTEGER) FROM dbo.LCNos(@LCNos, ',') )
END
and finally passing string comma separated ids from jquery:
function chk()
{
$('.Checkbox:checked').map(function () {
return $(this).attr('data-lcno');
}).get().join(',')
}
data-lcno is data attribute to checkboxlist.