开发者

SQL Server 2008 Stored Procedure

开发者 https://www.devze.com 2022-12-18 13:14 出处:网络
I cannot store the date data type variables using stored procedure.My code is: ALTER PROCEDURE [dbo].[Access1Register]

I cannot store the date data type variables using stored procedure. My code is:

ALTER PROCEDURE [dbo].[Access1Register] 
 -- Add the parameters for the stored procedure here
 @MobileNumber int, 
 @CitizenName varchar(50),
 @Dob char(8),
 @VerificationCode int
AS
BEGIN
 -- SET NOCOUNT ON a开发者_运维知识库dded to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

    -- Insert statements for procedure here
    select CAST(@dob As DATE)
 Insert Into Access1 (MobileNo,CitizenName,Dob,VerificationCode)
 values(@MobileNumber,@CitizenName,@Dob,@VerificationCode)
go

If I exec this procedure it is executing, but there is an error occured in the date type variable. It's raising the error as invalid item '-'.


It depends on how you pass in the @Dob values.

Your best bet is to use the ISO8601 format - 'YYYYMMDD' - since that will always convert to DATE properly - regardless of your language and regional settings on your SQL Server machine.


It depends on the date format that you pass.

If it is 'mm-dd-yy' you can use CONVERT(DATE, @Dob, 110), if it is 'dd-mm-yy' then CONVERT(DATE, @Dob, 105).


In which format you are passing the @Dob values? And what error you are getting exactly?

If you will pass the @Dob values in the format of mm-dd-yy, it should work correctly and no errors will be there.

0

精彩评论

暂无评论...
验证码 换一张
取 消