Конфликт между datetime и varchar

DECLARE  
@ReceiverID NUMERIC(18, 0),
@datebegin DATETIME,
@dateend DATETIME,
@ResponsibleStaff NUMERIC(18, 0),
@priceListType INT,
@ContractID NUMERIC(18, 0);
BEGIN TRY
    SELECT 
    @ContractID = ISNULL(ContractID, -1),
    @ReceiverID = ReceiverID,
    @ResponsibleStaff = ResponsibleStaff,
    @datebegin = datebegin,
    @dateend = dateend,
    @priceListType = priceListType
    FROM OPENXML(@idoc, '/root/filter')
    WITH 
    (
            ReceiverID NUMERIC(18, 0),
            ResponsibleStaff NUMERIC(18, 0),
            priceListType INT,
            datebegin DATETIME,
            dateend DATETIME,
            ContractID numeric(18, 0)
    )
**@datebegin DATETIME,
@dateend DATETIME,**

INSERT INTO #Contract(NoteNumber, ContractID, NoteDate)
SELECT ot.NoteNumber, ot.ContractID, ot.NoteDate
FROM dbo.tbCNOutcoming ot
WHERE ot.ContractID = 326073625360601 and ot.NoteDate BETWEEN  **FORMAT(@datebegin, 'yyyy-MM-ddThh:mm:ss')  AND FORMAT(@dateend, 'yyyy-MM-ddThh:mm:ss')**
INSERT INTO #PriceFact(NoteNumber, NoteDate, ContractorName, Amount,
                     Currency, RateRUS, RateUSD, PriceUSD, CenaOpl, PriceListType, Factor)
    SELECT 
           fgr.NoteNumber,
           fgr.NoteDate,
           fgr.ContractorName,
           fgr.Amount,
           fgr.Currency,
           fgr.RateRUS,
           fgr.RateUSD,
           fgr.PriceUSD,
           fgr.CenaOpl,
           fgr.PriceListType,
           fgr.Factor
    FROM dbo.fGetReport2706(405, **FORMAT(@dateend, 'yyyy-MM-ddThh:mm:ss') , FORMAT(@datebegin, 'yyyy-MM-ddThh:mm:ss')**, -1,@ReceiverID,
                           -1, -1, -1, -1) fgr;

В данном случае, оно ничего не выводит,но если написать вручную дату,то все нормально,но мне нужно все через переменную т.к значения туда попадает с фильтра

INSERT INTO #Contract(NoteNumber, ContractID, NoteDate)
SELECT ot.NoteNumber, ot.ContractID, ot.NoteDate
FROM dbo.tbCNOutcoming ot
WHERE ot.ContractID = 326073625360601 and ot.NoteDate BETWEEN  **'2023-12-01T00:00:00'  AND '2023-12-31T00:00:00'**
INSERT INTO #PriceFact(NoteNumber, NoteDate, ContractorName, Amount,
                     Currency, RateRUS, RateUSD, PriceUSD, CenaOpl, PriceListType, Factor)
    SELECT 
           fgr.NoteNumber,
           fgr.NoteDate,
           fgr.ContractorName,
           fgr.Amount,
           fgr.Currency,
           fgr.RateRUS,
           fgr.RateUSD,
           fgr.PriceUSD,
           fgr.CenaOpl,
           fgr.PriceListType,
           fgr.Factor
    FROM dbo.fGetReport2706(405, **'2023-12-31T00:00:00' , '2023-12-01T00:00:00',** -1,@ReceiverID,
                           -1, -1, -1, -1) fgr;

Что можно сделать с форматами?


Ответы (0 шт):