Запрос:
--Структура таблицы
Код: Выделить всё
Create Table MyTable (
ID int,
Query varchar(max)
)
Код: Выделить всё
UPDATE MyTable
SET Query = '{{child query}}'
WHERE ID = @ID;
Код: Выделить всё
Declare @ServiceIDsTableString as varchar(20) Set @ServiceIDsTableString = @ServiceIDsString Declare @ServiceIDs Table ( ServiceID INT PRIMARY KEY CLUSTERED ) DECLARE @OrderID varchar(10), @Pos int SET @ServiceIDsTableString = LTRIM(RTRIM(@ServiceIDsTableString))+ ',' SET @Pos = CHARINDEX(',', @ServiceIDsTableString, 1) IF REPLACE(@ServiceIDsTableString, ',', '') '' BEGIN WHILE @Pos > 0 BEGIN SET @OrderID = LTRIM(RTRIM(LEFT(@ServiceIDsTableString, @Pos - 1))) IF @OrderID '' BEGIN INSERT INTO @ServiceIDs (ServiceID) VALUES (CAST(@OrderID AS int)) END SET @ServiceIDsTableString = RIGHT(@ServiceIDsTableString, LEN(@ServiceIDsTableString) - @Pos) SET @Pos = CHARINDEX(',', @ServiceIDsTableString, 1) END END Declare @CurrentTime_UTC as DateTime select @CurrentTime_UTC = GETUTCDATE() Declare @ProviderTripIDs Table ( ProviderTripID varchar(255) ) insert into @ProviderTripIDs select ProviderTripID FROM MfTrips mt with (nolock) INNER JOIN Mfs m with (nolock)on m.MfID = mt.MfID inner join MfDatas md with (nolock) on md.MfDataID = m.MfDataID inner join locations lp with (nolock) on mt.PickLocationID = lp.LocationID inner join Locations ld with (nolock) on mt.DropLocationID = ld.LocationID inner join Customers c with (nolock)on mt.CustomerID = c.CustomerID inner join Reservations r with (nolock) on r.ReservationID = mt.ReservationID where m.active = 1 and r.ParentReservationID = 0 and m.date = @Date and mt.ProviderID = 1 and mt.MfTripStatusID = 1 and mt.ModeID = 3 and mt.PassengerTypeID in (select PassengerTypeID from PassengerTypes with (nolock) where CorePassengerTypeID = 1) and mt.ServiceID in (select ServiceID from @ServiceIDs) and md.MfDataTypeID = dbo.GetCurrentMfDataTypeID(m.Date) and (mt.WillCall = 0 or mt.WillCallReadyAt >= '1/1/2000') and m.description = 'Unassigned' and mt.LevelOfServiceID = 1 and mt.TripPurposeID not in (1) and dbo.GetAge(c.BirthDate, m.Date) < 75 and (dbo.GetAge(c.BirthDate, m.Date) > 18 or 1 = (select top 1 1 from MfTripExtraPassengers imtep with (nolock) where imtep.MfTripID = mt.MfTripID and imtep.Deleted_UTC is null and dbo.GetAge(imtep.BirthDate, m.Date) > 18) ) and (select count(*) from MfTripExtraPassengers imtep with (nolock) where imtep.MfTripID = mt.MfTripID and imtep.Deleted_UTC is null ) m.Date then mt.ScheduledPickWindowBegin AT TIME ZONE (select Value from ClientSettings where ClientSettingID = 22) when mt.scheduledDropWindowEnd
Подробнее здесь: [url]https://stackoverflow.com/questions/79175563/how-to-use-query-with-quotes-inside-a-parent-query[/url]