CodeProject Assume you've been asked to return a date stored as a datetime2 in a specific format using Transact-SQL. For SQL Server 2012+, one option is to use T-SQL's FORMAT() function. FORMAT() is used with either a .NET format string or a custom formatting string to determine the formatting that should be applied. Starting with … Continue reading Formatting Dates in T-SQL Using CONVERT with Style Codes
Tag: CONVERT
Querying Stored Procedure and System Function Parameter Information
Tested on: SQL Server 2016 Developer Edition Accurate as of: January, 2018The following snippet generates a SQL Server View that displays information about the parameters that need to be passed in to System Objects. The data type information that is returned in this view is human readable (i.e. `nvarchar(200) NULL`), rather than the numeric type … Continue reading Querying Stored Procedure and System Function Parameter Information
Return DDL from METADATA
Tested on server version: SQL Server 2016 Developer Edition Reference info accurate on: January, 2018 The following script demonstrates how to generate each column's DDL from metadata in Transact-SQL. Example Output: T-SQL [code language="sql"] DECLARE @rundate datetime2 = getdate(); DECLARE @default_collation nvarchar(128); -- = 'SQL_Latin1_General_CP1_CI_AS'; SELECT @default_collation = convert(sysname, serverproperty('collation')) SELECT TABLE_CATALOG ,TABLE_SCHEMA ,TABLE_NAME ,COLUMN_NAME … Continue reading Return DDL from METADATA