Hello
I have this insert statement i want to create a sql function or store procedure which first truncate the table and then run this insert statement how to do it
I tried to create sql function like this
SET IDENTITY_INSERT [dbo].[Order_Master_V2] ON
GO
INSERT [dbo].[Order_Master_V2] ([OrderMasterId], [OrderMasterGUID], [OrderMasterCustomGUID], [InsertDate], [UpdatedDate], [BuyerId], [OrderStatus], [LastOrderStatus], [BuyerNotes], [VendorNotes], [ProductId], [CurrencyId], [ActualPrice], [ProductPrice], [ProductAttributePrice], [ProductDiscount], [QTY], [PaymentMode], [PaymentDate], [PaymentReferenceId], [CommissionPercentage], [CommisionAmount], [IsCoupon], [CouponCode], [CurrencyConversionRate], [ConversionCurrencySymbol], [DeliveryStatusId], [ProductJobAppliedGUID], [GroupOrderGeneratedGUID]) VALUES (1, N'd37d7d64-8583-4de2-8556-be21d63349f8', N'659ba66d-d610-4355-97ab-013029274447', CAST(N'2023-03-16T10:16:24.093' AS DateTime), NULL, 1188, N'Confirm', NULL, N'', NULL, 134, 1, CAST(49.00 AS Decimal(18, 2)), CAST(49.00 AS Decimal(18, 2)), CAST(49.00 AS Decimal(18, 2)), CAST(0.00 AS Decimal(18, 2)), 1, NULL, NULL, NULL, CAST(0.00 AS Decimal(18, 2)), CAST(0.00 AS Decimal(18, 2)), 0, N'', CAST(0.00 AS Decimal(18, 2)), N'USD', 19, NULL, N'd8d0aff6-abfb-4dca-bee4-dcd388b9f2fb')
GO
SET IDENTITY_INSERT [dbo].[Order_Master_V2] OFF
GO
CREATE FUNCTION refreshdata
(
-- Add the parameters for the function here
)
RETURNS TABLE
AS
RETURN
(
INSERT [dbo].[Order_Master_V2] ([OrderMasterId], [OrderMasterGUID], [OrderMasterCustomGUID], [InsertDate], [UpdatedDate], [BuyerId], [OrderStatus], [LastOrderStatus], [BuyerNotes], [VendorNotes], [ProductId], [CurrencyId], [ActualPrice], [ProductPrice], [ProductAttributePrice], [ProductDiscount], [QTY], [PaymentMode], [PaymentDate], [PaymentReferenceId], [CommissionPercentage], [CommisionAmount], [IsCoupon], [CouponCode], [CurrencyConversionRate], [ConversionCurrencySymbol], [DeliveryStatusId], [ProductJobAppliedGUID], [GroupOrderGeneratedGUID])
VALUES (1, N'd37d7d64-8583-4de2-8556-be21d63349f8', N'659ba66d-d610-4355-97ab-013029274447', CAST(N'2023-03-16T10:16:24.093' AS DateTime), NULL, 1188, N'Confirm', NULL, N'', NULL, 134, 1, CAST(49.00 AS Decimal(18, 2)), CAST(49.00 AS Decimal(18, 2)), CAST(49.00 AS Decimal(18, 2)), CAST(0.00 AS Decimal(18, 2)), 1, NULL, NULL, NULL, CAST(0.00 AS Decimal(18, 2)), CAST(0.00 AS Decimal(18, 2)), 0, N'', CAST(0.00 AS Decimal(18, 2)), N'USD', 19, NULL, N'd8d0aff6-abfb-4dca-bee4-dcd388b9f2fb')
)
GO
but it gives error Msg 156, Level 15, State 1, Procedure refreshdata, Line 17 [Batch Start Line 15] Incorrect syntax near the keyword 'INSERT'. Msg 102, Level 15, State 1, Procedure refreshdata, Line 21 [Batch Start Line 15] Incorrect syntax near ')'.