March 1, 2010 at 7:27 am
I'm trying to write a C# CLR stored procedure which needs to take a datetime2(3) as a parameter.
However, mapping the parameter as a SqlDateTime causes the error:
CREATE PROCEDURE for "myProcedure" failed because T-SQL and CLR types for parameter "@startDT" do not match.
It appears that SqlDateTime still maps to the SQL DateTime accurate to 3.3 millisecs
Any ideas appreciated as I'm now very confused.
March 1, 2010 at 9:41 pm
jm99 (3/1/2010)
It appears that SqlDateTime still maps to the SQL DateTime accurate to 3.3 millisecs
SqlDateTime still maps to the SQL Server datetime data type, yes. If I remember correctly, I think the System.DateTimeOffset type will accept a datetime2 without complaint or loss of precision.
E.g.:
[Microsoft.SqlServer.Server.SqlFunction]
[return: SqlFacet(MaxSize=21)]
public static SqlString datetime2_test( DateTimeOffset datetime )
{
if ( datetime == null )
return DateTime.Now.ToString( "yyyyMMddHHmmssfffffff" );
else
return datetime.ToString( "yyyyMMddHHmmssfffffff" );
}
March 2, 2010 at 2:37 pm
What is the CLR for? I mean, what is it supposed to do?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply