Hello,
I am using GETDATE() in my SQL statement but I've got this error when I run my windows application form:
Additional information: Conversion failed when converting date and/or time from character string.
This is the stored procedure
USE [PharmacyDB]
GO
/****** Object: StoredProcedure [dbo].[storedP] Script Date: 2014-06-07 00:54:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[storedP]
(@prdctName nvarchar(50)
,@ordrdQnty int
--,@OrderID int
,@ordrPrice money
,@TrnDate datetime = GETDATE
--,@TrnTotal decimal=90.000
)
as
BEGIN TRY
begin transaction trs
DECLARE @TrnId int
SET @TrnId = 'SCOPE_IDENTITY'
INSERT INTO [dbo].[OrderProduct]
(--[OrdrId],
[prdctName]
,[ordrdQnty]
,[ordrPrice]
--,[TrnId]
)
VALUES
(--@OrderID,
@prdctName
,@ordrdQnty
,@ordrPrice
--,@TrnId
)
INSERT INTO [dbo].[Transaction]
(
--[OrdrId],
[TrnDate]
--,[TrnTotal]
)
VALUES
(-- @OrderId ,
-- CONVERT(timestamp,GETDATE())
GETDATE()
--(select CURRENT_TIMESTAMP )
--,@TrnTotal
-- (SELECT
-- t1.OrdrId,
-- t1.ordrPrice,
-- SUM(t2.ordrPrice) AS SUM
--FROM OrderProduct t1
--INNER JOIN OrderProduct t2 ON t1.OrdrId >= t2.OrdrId
--GROUP BY t1.OrdrId,
-- t1.ordrPrice
--ORDER BY (t1.OrdrId)
-- )
)
commit tran
return 0
END TRY
BEGIN CATCH
rollback
return 1
END CATCH
Thanks in advanced.
ALTER proc [dbo].[storedP] (@prdctName nvarchar(50) ,@ordrdQnty int --,@OrderID int ,@ordrPrice money ,@TrnDate datetime = NULL-- GETDATE --,@TrnTotal decimal=90.000 ) as BEGIN TRY begin transaction trs DECLARE @TrnId int SET @TrnId = 'SCOPE_IDENTITY' INSERT INTO [dbo].[OrderProduct] (--[OrdrId], [prdctName] ,[ordrdQnty] ,[ordrPrice] ) VALUES ( @prdctName ,@ordrdQnty ,@ordrPrice ) IF @TrnDate IS NULL SET @TrnDate = CURRENT_TIMESTAMP; INSERT INTO [dbo].[Transaction] ( [TrnDate] --,[TrnTotal] ) VALUES ( GETDATE() --,@TrnTotal -- (SELECT -- t1.OrdrId, -- t1.ordrPrice, -- SUM(t2.ordrPrice) AS SUM --FROM OrderProduct t1 --INNER JOIN OrderProduct t2 ON t1.OrdrId >= t2.OrdrId --GROUP BY t1.OrdrId, -- t1.ordrPrice --ORDER BY (t1.OrdrId) -- ) ) commit tran return 0 END TRY BEGIN CATCH rollback return 1 END CATCH