I am using a dynamic SQL query in a stored procedure since the table name varies. Part of the query converts a
smalldatetime to VARCHAR (since the dynamic SQL query is in a string), but zeroes out the seconds. I need the exact seconds. How do I get around this?
First of all, I would be remiss in my duties as a SQL Server educator if I didn't chastise you for passing in a dynamic table name to a stored procedure! Doing so
your application code to your database code. This means that any change in your database (i.e. a change in table names) will require that you also change your application. That is not a good situation to be in. Databases, I believe, do their best jobs as centralized, black-box storage mechanisms that can be shared amongst multiple applications, without code change in every application with every database change. As for the
, I'm afraid you're out of luck. That datatype is only accurate to the minute. For second (and three millisecond) accuracy, you'll have to use
Do you have comments on this Ask the Expert Q&A? Let us know.
Dig Deeper on SQL Server Stored Procedures
Multiple readers can sometimes read the same row simultaneously causing a false result. SQL Server 2005 expert Adam Machanic suggests modifying the ...
Migrating to SQL Server 2005 from SQL Server 2000 is a hefty feat when compared to upgrading from 7.0 to SQL Server 2000. Site expert Adam Machanic ...
SQL Server 2005 and T-SQL do have differences. The advantages and disadvantages would depend user environment as described by SQL Server 2005 expert...
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.