Solved

Problem constructing a dynamic SQL statement - date and numeric parameters cause error; string parameters OK

Posted on 2013-01-28
3
334 Views
Last Modified: 2013-01-28
The web application uses a set of Microsoft tables and stored procedures. In this case, I want to repeatedly invoke aspnet_Membership_CreateUser. 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
0
Comment
Question by:dmaclean2
  • 2
3 Comments
 

Author Comment

by:dmaclean2
ID: 38829882
As an added reference to my question, here are the parameters required by the stored procedure that I am trying to call
CREATE PROCEDURE [dbo].[aspnet_Membership_CreateUser]
    @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
0
 
LVL 15

Accepted Solution

by:
Eyal earned 500 total points
ID: 38829901
as it says: the format of the dates are invalid as dates. convert the string dates from the recordset to yyyyMMdd HH:nn and send them in this format to the SP
0
 

Author Closing Comment

by:dmaclean2
ID: 38830056
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!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
T-SQL for SS2000 -- get characters until a digit 6 19
VS2015 Redefinition errors 4 27
Error running stored procedure 11 15
Sql Query 4 14
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now