Douglass MacLean
asked on
Problem constructing a dynamic SQL statement - date and numeric parameters cause error; string parameters OK
The web application uses a set of Microsoft tables and stored procedures. In this case, I want to repeatedly invoke aspnet_Membership_CreateUs er. I have a SELECT statement that provides the parameters to pass to that sp.
And I have a set of code modeled on one I found on the web that provides the logic to go through that recordset row by row and call the sp.
The problem is that the construction of the specific SQl statement to execute (@SQLExec) fails for the two date parameters, '@CurrentUTCDate' and '@CreatedDate'
Here is the error message for '@CurrentUTCDate'
Msg 241, Level 16, State 1, Line 33
Conversion failed when converting date and/or time from character string.
I have tried every combination of quotes I can think of and none of them work.
The attached file is a stripped-down duplicate of my current stored procedure.
Test-generate-membership-proc.sql
And I have a set of code modeled on one I found on the web that provides the logic to go through that recordset row by row and call the sp.
The problem is that the construction of the specific SQl statement to execute (@SQLExec) fails for the two date parameters, '@CurrentUTCDate' and '@CreatedDate'
Here is the error message for '@CurrentUTCDate'
Msg 241, Level 16, State 1, Line 33
Conversion failed when converting date and/or time from character string.
I have tried every combination of quotes I can think of and none of them work.
The attached file is a stripped-down duplicate of my current stored procedure.
Test-generate-membership-proc.sql
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I lost sight of that fact that a SQL statement is, by definition, a character string. All non-character data (datetime, bit, float, etc.) needs to be converted to nvarchar.
Silly me.
Good you!
Silly me.
Good you!
ASKER
CREATE PROCEDURE [dbo].[aspnet_Membership_C
@ApplicationName nvarchar(256),
@UserName nvarchar(256),
@Password nvarchar(128),
@PasswordSalt nvarchar(128),
@Email nvarchar(256),
@PasswordQuestion nvarchar(256),
@PasswordAnswer nvarchar(128),
@IsApproved bit,
@CurrentTimeUtc datetime,
@CreateDate datetime = NULL,
@UniqueEmail int = 0,
@PasswordFormat int = 0,
@UserId uniqueidentifier OUTPUT