views:

43

answers:

2

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 added 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 '-'.

+2  A: 

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' CONVERT(DATE, @Dob, 105)

sergiom
+3  A: 

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.

marc_s