这是我希望INSERT
在存储过程中使用的场景。
表:
tbl速率
- RateID (pk)
- 给钱打分
- 天数
- isDailyRate 位
tblBooking
- 总钱
在我的 vb 应用程序中,这是声明。我如何将它翻译成 T-SQL?
if !isDaily = True then
!Totals = (!Days * !Rate)
else
!Totals = !Rate
end if
这是我的存储过程:
Create PROCEDURE [dbo].[sp_tblBooking_Add]
(
@RateID bigint,
@Rate money,
@Days int,
@CheckOUT datetime
)
AS
BEGIN
--Below is the logic I want. I can't get the right syntax
--Declare @myTotals as money
--Declare @myCheckOut as DateTime
--if (Select isDailyRate FROM tblRates WHERE (RateID = @RateID)) = True THEN
-- set myTotals = (@Rate * @Days)
-- set @CheckOUT = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) + @Days, '12:00')
--Else
-- set myTotals = @Rate
-- set @CheckOUT = GETDATE()
--End if
INSERT INTO tblBooking(Totals, CheckOUT)
VALUES(@myTotals, @myCheckOut);
END